Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert string 1/4 or 1/2 to numeric
Message
De
20/01/2016 16:22:16
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
 
À
20/01/2016 13:48:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01629854
Message ID:
01630005
Vues:
62
>>>>>>There shoud be a way using LOG10() without counting numbers, but I'm to lazy right now. (For the whole part it's INT(log10(ABS(EVL(INT(tnNumber),1))))+1 )
>>>>>
>>>>>Understood!
>>>>>Thank you.
>>>>
>>>>Hi Bill,
>>>>
>>>>I did not found a simple way to calculater the decimal digits wit LOG.
>>>>So the kludge for stuff based 2: (I had some fun with it):
>>>>
>>>>CLEAR
>>>>
>>>>?GetCommonFract_2(1)
>>>>?GetCommonFract_2(0)
>>>>?GetCommonFract_2(13/32)
>>>>?GetCommonFract_2(0.25)
>>>>?GetCommonFract_2(9/16)
>>>>?GetCommonFract_2(31/16)
>>>>?GetCommonFract_2(-15.125)
>>>>
>>>>FUNCTION GetCommonFract_2
>>>> LPARAMETERS;
>>>>  tnNumber
>>>>
>>>> LOCAL;
>>>>  lnWhole,;
>>>>  lnFrac,;
>>>>  lnNominator
>>>>
>>>> llSign      = SIGN(tnNumber)=-1
>>>> tnNumber    = ABS(tnNumber)
>>>> lnWhole     = INT(tnNumber)
>>>> lnFrac      = tnNumber-lnWhole
>>>> lnNominator = 2^(LEN(RTRIM(STR(lnFrac,15,15),"0"))-1)
>>>>
>>>> RETURN IIF(llSign,'-','')+;
>>>>  IIF(EMPTY(lnWhole),IIF(EMPTY(lnFrac),'0',''),LTRIM(STR(lnWhole,15))+' ')+;
>>>>  IIF(EMPTY(lnFrac),'',LTRIM(STR(lnFrac*lnNominator,15))+'/'+LTRIM(STR(lnNominator,15)))
>>>>ENDFUNC &&GetCommonFract_2
>>>>
>>>>
>>>>Edit: added parenthesis on 2^....
>>>
>>>a barbaric way to decimals count
>>>
>>>x = 1234.12777
>>>
>>>? MAX(LEN(CAST(x%1 AS M))-2,0)
>>>
>>
>>Some mixup of SET DECIMALS and SET FIXED or wathever brings it to return 2, because CAST(... returns "0,06".
>>STR(n,15,15) ist the only function to securly return all decimals.
>
>Sure ?
>CAST( as memo) work .

not with my general setting (so does transform and PADx). This is something with SET FIXED and SET DECIMALS. I have figured out whats causing it ages ago. But I can't remeber and I'm to lazy.
If CAST is working then PADx will work too. I have this setting for ages and know of it - but because I know it I do only use STR
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform