Home:ALL Converter>Math operations on integer or floating point values

Math operations on integer or floating point values

Ask Time:2016-01-13T19:17:04         Author:Yogesh Byndoor

Json Formatter

I can explain this with an example.

Consider the floating point values like 2.0, 3.0 e.t.c the output must the number i.e 2, 3 e.t.c

If the floating point values are like 2.1, 3.5 e.t.c the output remain the same i.e 2.1, 3.5

Is there any Math operation on floating point values to do this?

Author:Yogesh Byndoor,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34765254/math-operations-on-integer-or-floating-point-values
LordAnomander :

You can easily check if a float has decimal places.\n\nif (number % (int) number == 0)\n System.out.println((int) number); // you know it has no decimal places\nelse\n System.out.println(number); // it has decimal places and you want to print them\n\n\nThe link provided by Seffy Golan suggests an even better solution, by simply comparing\n\nif (number == (long) number) { ... }\n\n\nI thought I'd take it into my answer as it is a nice approach I wasn't aware of.",
2016-01-13T11:29:39
yy