Data type: very high integer

simple question:

we just try to calculate the length of a lightyear.

using int a = 300000 * // m/s — error ---- km/s
60*60 * // to km/h
24 * // day
365; // year
But rounding error occurs

Unclear why

(I understand int is only up to 32000)

So I’d like to ask: which data type I need to use, long, double or Integer?

I need longInt in theory, what is this called?

1 Like

An int can store integers approximately +/-2000000000 so a long data type might be suitable but if you want fractional values the double data type gives 15/16 significant digits

1 Like

No fractionally needed

But using text() command I receive a rounding error before the . dot (!)

1 Like

The result is 9 trillion kilometers so this could be the
issue

Do we have a longer integer data type

1 Like

Shouldn’t be a dot with an integer value probably due to some data type conversion by Processing

Use long instead of int for bigger values

1 Like

If you use long then I suggest you use native Java to convert to a string before passing to text

3 Likes

Hello,

I have run into this issue before.
Units for speed of light corrected.
I changed everything to meters.
Don’t forget the L.

References:

:)

3 Likes

Thanks.

The reason for the error was the internal conversion
to String performed by the text() command.

When you convert the value as shown (or convent before the
text() command and bring the result in a new String var)
and use text() then, you are good.

1 Like