You could concatenate an if() statement that adds a leading zero.
instead of what you're doing now:
___other stuff___ & yourfield & ___other stuff___
you would do:
___other stuff___ & if ( left (yourfield ; 1) = "." ; "0" & yourfield ; yourfield ) & ___other stuff___
where "yourfield" is the field returning the decimal, and "other stuff" is the rest of the string.
Or if the value was entered in (raw data) as 0.45 and not .45, you might be able to simply use GetAsText( yourfield ) as well.
I had deleted my suggestion since it is limited but I decided to put it back in case it is still useful. We need to know how many places are possible in those numbers ... we aren't dealing with true numbers where they are unlimited ... with text functions we must be specific to address all possible combinations and know how much to pad.
So I decided to punt and provide two possibilities. if decimals are allowed as ##.##, use:
Let ( [
n = Right ( "00" & Int ( decimalField ) ; 2 ) ;
m = Middle ( Mod ( decimalField ; 1 ) & "00" ; 2 ; 2 )
n & "." & m
... and if the format should be #.## then change n to: Right ( "0" & Int ( decimalField ) ; 1 )
EDITED: Provided alternate calculations depending upon text format required
Thank you, I will play around with this later. Should it be used as a custom function?
It doesn't need to be used as a custom function; regular calculation would work fine.
How about this custom function:
If ( Num < 0 ; "-" ; "" ) &
Let ( [ Integer = 0 + Int ( Abs ( Num ) ) ;
Decimal = Substitute ( Abs ( Round ( Num ; If ( Precision > 6 ; 6 ; Precision ) ) ) - Integer ; "." ; "" ) ] ;
If ( IsEmpty ( Num ) ; "" ; Integer & "." & Left ( Decimal & "000000" ; If ( Precision > 6 ; 6 ; Precision ) ) ) )
The parameters are Num and Precision. It can round up to 6 decimals but you can change the precision if you want.
I use FM Pro 12. Try turning the numbers into string variables before you concatenated.
I wanted to make a unique record bar code value that concatenated the record number plus the zip code plus four without the dash. Here is the code I used:
Enter Browse Mode
Go to Record/Request/Page [First]
Set Variable [$$ZipString; Vaule:Left (MyDirectory::Zip ; 5 )]
Set Variable [$$ZipStringPlus; Vaule:Right (MyDirectory::Zip ; 4 )]
Set Variable [$$ZipStringNoDash; Value:$$ZipString & $$ZipStringPlus]
Set Variable [$$RecNum; Vaule: MyDirectory::RecordNum + 10000]
Set Variable [$$SetBarCode; Value:$$RecNum & $$ZipStringNoDash]
Set Field [MyDirectory:BarCode; $$SetBarCode]
Go to Record/Request/Page [Next; Exet after last]