java - - Rounding a double up & removing the numbers after a decimal point - -


Can anyone tell me how I & amp; Then remove the numbers after the decimal places - & amp; Then convert this number to string?

For example, start with a double value of 55.6666666666667 - Make it round to double value of 56.0000000000 -

or start with 55.333333333333 - below the double value of 55.0000000000 -

& amp; Then delete the decimal point and convert it back to zero-string.

Thank you.

The best way to round a value for the nearest integer is: < Pre> int x = (int) math. (55.6666666666667);

x will be 56. To use x a string at the end to round up or down, respectively, you Math.ceil () and Math.floor () For String.valueOf () . Like this:

  string xString = String.valueOf (x);   

If you want to do this in one line:

  string xString = String.valueOf (Math Field (55.6666666666667));   

You can read more about the math category and the string class.

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -