Roku Developer Program

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

INT Conversion

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:

but this returns 20715916
instead of 20715915

Can anyone help me here?

0 Kudos
Level 12

Re: INT Conversion

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

0 Kudos

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)

0 Kudos
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