To put comma's into the integer part,
I find the following to much easier to look at.
Also the logic is easy to convert to a CF is you want
to use it in a field def.
Set Variable [$IsNeg; case(getasnumber($n) < 0; 1; 0 )]
Set Variable [$n; Abs($n)]
Set Variable [$intNum; Int($n)]
If [Length($intNum) > 3]
Set Variable [$intNum;
left($intNum;length($intNum)-3) & "," & right($intNum;3)]
If [Length($intNum) > 7]
Set Variable [$intNum;
left($intNum;length($intNum)-7) & "," & right($intNum;7)]
If [Length($intNum) > 11]
Set Variable [$intNum;
left($intNum;length($intNum)-11) & "," & right($intNum;11)]
EndIf
EndIf
EndIf
that'll take you out to 999,999,999,999
To add the decimal part (with $dPlace = # of decimal places):
Set Variable [$dZeros; left("000000000000"; $dPlaces)]
Set Variable [$dValue; getasnumber($n) - getasnumber($intNum)]
If [Getasnumber($dValue) = 0]
Set Variable [$dPart; "." & $dZeros]
Else
Set Variable [$dPart; "." &
middle(getastext(round(getasnumber($dValue);$dPlaces)) &
$dZeros; 2; $dPlaces )]
EndIf
Set Variable [$returnStr; $intNum & $dPart]
You can throw in a $ sign, and decide where you want to add
a minus sign, using $IsNeg.
-----Original Message-----
From: David Haney Sent: Tuesday, October 20, 2009 5:02 PM
Danny Lopez,
You wrote...
> Does anyone know how to transform 123456.78 to "123,456.78"?
> I need a function which transforms a number into this format of text.
(1) For the exact length shown...
Left ( num ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & Right ( num ; 3 )
(2) For multiple lengths of a number AND assuming a decimal is always
entered...
Case (
Length ( num ) = 3 ; Right ( num ; 3 ) ;
Length ( num ) = 4 ; Left ( num ; 1 ) & Right ( num ; 3 ) ;
Length ( num ) = 5 ; Left ( num ; 2 ) & Right ( num ; 3 ) ;
Length ( num ) = 6 ; Left ( num ; 3 ) & Right ( num ; 3 ) ;
Length ( num ) = 7 ; Left ( num ; 1 ) & "," & Middle ( num ; 4 ; 3 ) &
Right ( num ; 3 ) ;
Length ( num ) = 8 ; Left ( num ; 2 ) & "," & Middle ( num ; 4 ; 3 ) &
Right ( num ; 3 ) ;
Length ( num ) = 9 ; Left ( num ; 3 ) & "," & Middle ( num ; 4 ; 3 ) &
Right ( num ; 3 ) ;
Length ( num ) = 10 ; Left ( num ; 1 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & Right ( num ; 3 ) ;
Length ( num ) = 11 ; Left ( num ; 2 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & Right ( num ; 3 ) ;
Length ( num ) = 12 ; Left ( num ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & Right ( num ; 3 ) ;
Length ( num ) = 13 ; Left ( num ; 1 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & Right ( num ; 3 )
;
Length ( num ) = 14 ; Left ( num ; 2 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & Right ( num ; 3 )
;
Length ( num ) = 15 ; Left ( num ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & Right ( num ; 3 )
;
Length ( num ) = 16 ; Left ( num ; 1 ) & "," & Middle ( num ; 4 ; 3 ) & ","
& Middle ( num ; 4 ; 3 ) & "," & Middle ( num ; 4 ; 3 ) & "," & Middle (
num ; 4 ; 3 ) & Right ( num ; 3 ) ;
)
There's other alternative but that should get you on your way...
David Haney
ADVANCED DATABASE SYSTEMS (ADS)
http://database-systems.comhttp://filemakeraccounting.com[hidden email]
(480) 588-8055
---------------------------------------
10323533 (ICQ)
davidhaney (Skype)
davidhaney (MAC)
david123haney (AIM)
david123haney (Gmail)
david123haney (Yahoo)
[hidden email] (MSN)
_______________________________________________
FMPexperts mailing list
[hidden email]
http://lists.ironclad.net.au/listinfo.cgi/fmpexperts-ironclad.net.au_______________________________________________
FMPexperts mailing list
[hidden email]
http://lists.ironclad.net.au/listinfo.cgi/fmpexperts-ironclad.net.au