Question

I am using a formula field to concatonate 2 decimal values separated by a dash. However, I want the result to trim all unneccesary trailing zeros and decimal points for both values.

For example, I want values 10 and 8.5 to be "10 - 8.5". Now it shows "10.00 - 8.50".

The formula I am using is CSTR({field1}) + " - " + CSTR({field2}).

Was it helpful?

Solution

I believe this is what you're looking for:

Convert Decimal Numbers to Text showing only the non-zero decimals

Especially this line might be helpful:

StringVar text     :=  Totext ( {Your.NumberField} , 6 , ""  )  ;

The first parameter is the decimal to be converted, the second parameter is the number of decimal places and the third parameter is the separator for thousands/millions etc.

OTHER TIPS

CSTR({number_field}, 0, '')

The second placeholder is for decimals.

The last placeholder is for thousands separator.

i wrote a simple function for this:

Function (stringVar param)
(
    Local stringVar oneChar := '0';
    Local numberVar strLen := Length(param);
    Local numberVar index := strLen;

    oneChar = param[strLen];

    while index > 0 and oneChar = '0' do
    (
        oneChar := param[index];
        index := index - 1;
    );

    Left(param , index + 1);
)

You can also try using the replace function:

replace("10.00",".00","")

but it won't work if there are non-zero numbers after the decimal point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top