Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

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
Roku Guru

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.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.