is there a String Utils Library for formatting Floats
FormatFloat('$0.00', FTotal)
FloatToStrF ?
I was able to do what i needed with
'$' + format('%0.2f', [FTotal]);
but just curious if those routines exist somewhere?
is there a String Utils Library for formatting Floats
FormatFloat('$0.00', FTotal)
FloatToStrF ?
I was able to do what i needed with
'$' + format('%0.2f', [FTotal]);
but just curious if those routines exist somewhere?
The underlying DWScript compiler yields a mini RTL, which contains string functions like the mentioned
Format(fmt: String; args: array of const): String. It also contains thefunction FloatToStr(f : Float; p : Integer = 99): String;which can work in this context as well.Unfortunately, the documentation of these mini RTL functions is yet a little bit unpretty, but you can get an idea what's supported at: https://bitbucket.org/egrange/dwscript/wiki/InternalStringFunctions.wiki#!internal-string-functions
Internally the functions map to
and
You can also write your own code to handle any string formats. The best would be to write a float helper so that you could write something like:
This however would add the toMyFormat extension for all float values. If you want to limit it to a new type you can write something like this:
I hope this helps.