Whenever i attempt to print a float i get 7.597e+09. Thats without to string. And when i try to use .ToStr() i still get 7.597e+09. I dont know how to correct this.
There's an undocumented Format method on strings that can be used like this. The string has a C-like printf format string, and the Format method takes the arguments and applies them to the % parameters.
Brightscript Debugger> ? 7.957e+09
7.957e+09
Brightscript Debugger> ? "%2.5f".Format(7.97e+9)
7969999872.00000
There's an undocumented Format method on strings that can be used like this. The string has a C-like printf format string, and the Format method takes the arguments and applies them to the % parameters.
Brightscript Debugger> ? 7.957e+09
7.957e+09
Brightscript Debugger> ? "%2.5f".Format(7.97e+9)
7969999872.00000
@RokuBen wrote:There's an undocumented Format method on strings that can be used like this. The string has a C-like printf format string, and the Format method takes the arguments and applies them to the % parameters.
Brightscript Debugger> ? 7.957e+09
7.957e+09
Brightscript Debugger> ? "%2.5f".Format(7.97e+9)
7969999872.00000
I'm not sure if it was intentional to use a different value here for the example, but it confused me at first read. 🙂
With the original value I see:
Brightscript Debugger> x = 7.957e+09
Brightscript Debugger> ? "%2.5f".Format(x)
7957000192.00000
I assume that the extra 192 is due to limitation of Float precision.
If you use a Double value, which can be created using the '#' type suffix, it doesn't show that issue.
Brightscript Debugger> x = 7.957e+09#
Brightscript Debugger> ? "%2.5f".Format(x)
7597000000.00000
Also note, instead of using <string>.Format(), you can pass the format specified to <floatingPoint>.ToStr() directly.
Brightscript Debugger> x = 7.957e+09
Brightscript Debugger> ? x.ToStr("%2.5f")
7957000192.00000
Brightscript Debugger> x = 7.957e+09#
Brightscript Debugger> ? x.ToStr("%2.5f")
7597000000.00000