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: 
andysmith1965
Streaming Star

INT Conversion

HI
I'm getting an issue where an api response is returning a float for a user id, i.e
{"user_id"  :  20715915.0}

I want to convert this to an INT by applying:

INT(20715915.0)
but this returns 20715916
instead of 20715915

Can anyone help me here?

0 Kudos
3 REPLIES 3
necrotek
Roku Guru

Re: INT Conversion

though "INT" should return what you are expecting try "CINT"

https://developer.roku.com/docs/references/brightscript/language/global-math-functions.md

0 Kudos
andysmith1965
Streaming Star

Re: INT Conversion

Thanks for the quick response but CINT also returns the same, I've tried that already.

Brightscript Debugger> p CINT(20715915.0)
20715916

0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: INT Conversion

This is a limitation of the 32-bit IEEE floating point representation used by the BrightScript Float type, and the global functions Int and CInt which take a parameter of that type.

In your own calculations you may be able to use the BrightScript Double (and LongInteger) types if you need greater precision.

Unfortunately it is a known issue that for backward compatibility reasons the ParseJSON function will emit a Float value rather than Double for values that fit in the Float range, which may result in the IEEE precision/rounding issues with conversions such as you have found.

 

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.