Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning the number of decimals a field has
Message
From
27/01/2004 21:33:49
 
 
To
27/01/2004 13:46:54
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00820138
Message ID:
00871240
Views:
34
>>Yep. Very nicely done.
>>
>>Alan
>>
>>>>>Is there a function that will return how many decimal places a numberic field has? Something like LEN() for a character field. I know I can get it with AFIELDS but I only want to check one field and this returns all the fields then I need to find what the field number is in the array. Seems like a pain for something this simple.
>>>>
>>>>
Function DecCount(tnVal)
>>>>Local n
>>>>cVal = Alltrim(Padl(tnVal, 1000))
>>>>
>>>>Return Len(cVal - IIF(At('.', cVal) = 0, Len(cVal), At('.', cVal))
>>>>
>>>>? DecCount(AliasName.FieldName)
>>>>
>>>>Alan
>>>
>>>Thanks I shorted it down to
>>>
>>>ln_dec = LEN(TRIM(PADR(MOD(field, 1), 21))) - 2
>>>
>
>Nice i found what i need. But one prob : If your field looks like 0.12300
>
>U'll have ln_dec = 5
>
>It's possible to scan the field and then remove all "0" from the right side, but maybe there is an easy way to do it? (to not play with a "WHILE" or a "FOR")
>
>Ty.

I thought that was the point. If a number is 0.12300, then there are 5 decimals. Usually if a number is shown/entered with trailing zeros, it's because that depth of precision is required. Depending on the application, 0.12300 is not necessarily meant to be the same as 0.123. Scientific applications come to mind.

Alan
Previous
Reply
Map
View

Click here to load this message in the networking platform