Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Level 11

Double.toStr() trouble

It seems there is no way to convert Double to string without undue loss of precision:
Brightscript Debugger> dbl = 1.23456789D-12: ? type(dbl), dbl
Double           1.23456789e-12

Brightscript Debugger> ? dbl.toStr(), box(dbl).toStr(), str(dbl)
1.23457e-12     1.23457e-12      1.234568e-12

Brightscript Debugger> ? formatJson(dbl)
1.23457e-12

Not sure what the exact reason is, seems as if it gets piped into a Float first. I event tried a RokuKC-suggested hack with formatJSON() to no cigar. "Print" does it just fine, why can't the other stringifiers?!

PS. It can get weirder too:
Brightscript Debugger> d = 1.234567890123456789d+40: ? d
1.2345678901235e+40

Brightscript Debugger> ? d.toStr(), str(d), formatJson(d)
1.23457e+40      inf            1.23456789e+40
0 Kudos
1 REPLY 1
belltown
Level 9

Re: Double.toStr() trouble

I noticed that when I wrote my own FormatJson() function before it was implemented in the Roku OS. I was formatting Doubles using Str(), which didn't result in double precision, although I wasn't too surprised because Str() is defined as taking a Float argument, not a Double. However, I'm surprised (not really) that the roDouble implementation of ifToStr does not generate a double precision string representation. Looks like a bug to me.
https://github.com/belltown/
0 Kudos