Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Number of decimal places
Message
 
 
À
04/10/2010 04:08:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01483618
Message ID:
01483792
Vues:
42
>>>>I'm sure there is an obvious answer but it's the weekend ...
>>>>
>>>>Given a numeric variable which may or may not have digits after the decimal point, what would be the quickest way to know the number of digits that occur after decimal point, zero or more?
>>>
>>>quickest
>>>
>>>
>>>=MAX(LEN(CAST(m.Number % 1 AS M))-2,0)
>>>
>>>* significant decimals only
>>>
>>>=MAX(LEN(RTRIM(CAST(m.Number % 1 AS M),"0"))-2,0)
>>>
>>>
>>
>>How do you do the same with float type in SQL Server?
>
>The float type I use it rarely.
>Normally you should only use
>to perform calculations to simulate physical models.
>
>When I see a database full of float fields,
>instantly understand the level of those who designed it.
>
>On the issue:
>As an approximate numeric,
>count the decimal places is not very sensible.
>To do this you first need to cast it into a decimal,
>but by doing so you've decided how many places can have!
>1.345678E-78 For example, how many places do you have?
>
>But for many simple things are not well placed:
>
>select cast(CAST(CAST(1.1 as float) AS DEC(38,16)) as varchar(40))
>-- return 1.1000000000000001
>
>
>So my solution is:
>if you need to know the number of decimal places,
>do not use a float, but uses a decimal.

You can see my solution in the thread I mentioned to Tore - I also first need to convert to decimal and make a pick on the precision. I chose 11 digits as using higher precision changes the original number (as it was float 0.99 it will become 0.98000089, something like that).
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform