How to Avoid Rounding of Decimal Values in Java

When you manipulate numbers in Java, you can store them as integers, decimals, floats and doubles. Integers, when added together or stored in a variable, do not carry over any decimal places that the user attempts to assign to them. If you want to avoid this rounding of the decimals in Java, you need to ensure that you declare your number variables as decimals, not integers.

Instructions

    • 1

      Open your Java program in your editor of choice.

    • 2

      Declare your decimal variable by typing "decimal yourDecimalVariable;" on a new line in your program.

    • 3

      Set a value to your decimal variable, such as 5.289, by typing "yourDecimalVariable = 5.289;" in a new line in the program.

Related Searches:

References

Comments

Related Ads

Featured