Steve Dyke

Ranch Hand

Posts: 1754

1

posted 1 week ago

- 1

Scientific notation is just a way to write numbers. It has nothing to do with the calculation, or even with the number itself. In other words, there is no such thing as "preventing scientific notation on a calculation".

Whether a number is displayed in scientific notation or not, depends on how you let Java format and print the number. The easiest way to print a

Whether a number is displayed in scientific notation or not, depends on how you let Java format and print the number. The easiest way to print a

`double`value in "normal" notation is like this:
Stephan van Hulst

Saloon Keeper

Posts: 7376

130

posted 1 week ago

Also note that changing the number of decimals you use in a

`double`literal won't change the precision of it. Floating point numbers have a fixed precision. If you want arbitrary precision, use`BigDecimal`.*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

Steve Dyke

Ranch Hand

Posts: 1754

1

posted 1 week ago

I am trying to use it in an SQL string to add a record to a remote data base.

I got the scientific natation from the console as part of the message I got when it failed. I need to save it as a 10 digit integer. The number in the calculation is a 13 digit number(just trying to shrink it down to 10 digits).

Bear Bibeault wrote:How are you printing it out?

I am trying to use it in an SQL string to add a record to a remote data base.

I got the scientific natation from the console as part of the message I got when it failed. I need to save it as a 10 digit integer. The number in the calculation is a 13 digit number(just trying to shrink it down to 10 digits).

Stephan van Hulst

Saloon Keeper

Posts: 7376

130

posted 1 week ago

If it's an integer, why are you using

Maybe you can explain exactly what the number is supposed to represent and what the calculation is supposed to do.

`double`?Maybe you can explain exactly what the number is supposed to represent and what the calculation is supposed to do.

Steve Dyke

Ranch Hand

Posts: 1754

1

posted 1 week ago

The following code generates a long number of 13 digits:

My remote data field is an integer type that holds 10 digits.

If I subtract 1490000000000 from the long number I get a 10 digit number.

However, when I use the result in my SQL string to insert the record the number is represented in scientific notation.

Stephan van Hulst wrote:If it's an integer, why are you usingdouble?

Maybe you can explain exactly what the number is supposed to represent and what the calculation is supposed to do.

The following code generates a long number of 13 digits:

My remote data field is an integer type that holds 10 digits.

If I subtract 1490000000000 from the long number I get a 10 digit number.

However, when I use the result in my SQL string to insert the record the number is represented in scientific notation.

posted 1 week ago

Note that in your original line of code:

you are subtracting 1490000000000.00 off of the number, which is a

If you need a

you are subtracting 1490000000000.00 off of the number, which is a

`double`literal (because of the decimal point in the number). This means that the result of that whole calculation is`double`, a floating-point number, and not`long`, an integer.If you need a

`long`, then don't subtract a`double`value from the number; subtract a`long`value from the number instead:
Steve Dyke

Ranch Hand

Posts: 1754

1

posted 1 week ago

Thanks, this works great. However, I did not consider my seed number growing as fast as it has. Now the number is 1500063579542 and subtracting the 1490000000000L yields an 11 digit number.

I need a way to reduce any 13 digit number down to 10 digits. Is there a way to strip the last 3 digits off?

Jesper de Jong wrote:Note that in your original line of code:

you are subtracting 1490000000000.00 off of the number, which is adoubleliteral (because of the decimal point in the number). This means that the result of that whole calculation isdouble, a floating-point number, and notlong, an integer.

If you need along, then don't subtract adoublevalue from the number; subtract alongvalue from the number instead:

Thanks, this works great. However, I did not consider my seed number growing as fast as it has. Now the number is 1500063579542 and subtracting the 1490000000000L yields an 11 digit number.

I need a way to reduce any 13 digit number down to 10 digits. Is there a way to strip the last 3 digits off?

Campbell Ritchie

Sheriff

Posts: 54495

150