1
votes

How can I format double to string keeping the value of the decimal point, but without showing decimal point.

Example:

Double: 21.75

Format for

String: 0002175
1
Did you try calling FormatFloat() with (T)FormatSettings.DecimalSeparator set to #0? - Remy Lebeau
This way does not works, result in the following format 000021. I would like to leave only numbers without calling another function. Calling another function already works. But I believe it would be more elegant by formatting. - Marcoscdoni
I double-checked, and most uses of DecimalSeparator do not allow it to be #0 (one case does, but it does not apply here). You could, however, format the Double normally, then strip out the DecimalSeparator afterwards. Not ideal, but I don't see any other option: StringReplace(FormatFloat(...), DecimalSeparator, '', []) - Remy Lebeau

1 Answers

0
votes

You can do that manually in a single line like Remy suggests:

text := StringReplace(FormatFloat('0.00', yourNumber), DecimalSeparator, '', []);

That will format the float as you need and replace decimal separator symbol with nothing - effectively omitting it.

Take note to force trailing zeroes, so that your resulting numbers are in the same order of magnitude.