EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2016
01:25 PM
Double.toStr() trouble
It seems there is no way to convert Double to string without undue loss of precision:
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> 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
1 REPLY 1
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2016
04:27 PM
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.