Using integer is a good way
If 'i' is integer, then the whole part
i = 86399 / 3600
then the remainder (non-integer) is (86399 / 3600) - i
or remainder is -i + 86399 / 3600
[parens now needed but for clarity]
if i is not integer then use integer function (convert to) on the first division process
The number of places is not consequential, other than in defining the types for variables in the first place.
0
With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.
public class Fraction {
public static double digits(double d, int places) {
return (long)(d*Math.pow(10,places)+0.5)/Math.pow(10,places);
}
public static double digits(double d, long places) {
return (long)(d*Math.pow(10,places)+0.5)/Math.pow(10,places);
}
public static float digits(float d, int places) {
return (int)(d*Math.pow(10,places)+0.5)/(float)Math.pow(10,places);
}
public static float digits(float d, long places) {
return (int)(d*Math.pow(10,places)+0.5)/(float)Math.pow(10,places);
}
}
Usage:
* double x = 86399 / 3600;
* System.out.print( Fraction.digits(x,10) ); // Fraction.digits(double, number of places);
* // will output the double as : 23.9997222222 (10 placess)
* float y = 86399 / 3600;
* System.out.print( Fraction.digits(f,10) ); // Fraction.digits(float, number of places);
* // will output the float as : 23.9997222222 (10 placess)
3.2.1 Integral Types and Values
The values of the integral types of the Java Virtual Machine are the same as those for the integral types of the Java language (§2.4.1):
For byte, from -128 to 127 (-27 to 27-1), inclusive
For short, from -32768 to 32767 (-215 to 215-1), inclusive
For int, from -2147483648 to 2147483647 (-231 to 231-1), inclusive
For long, from -9223372036854775808 to 9223372036854775807 (-263 to 263-1), inclusive
For char, from 'u0000' to 'uffff'; char is unsigned, so 'uffff' represents 65535 when used in expressions, not -1
3.2.2 Floating-Point Types and Values
The largest positive finite floating-point literal of type double is 1.79769313486231570e+308. The smallest positive nonzero floating-point literal of type double is 4.94065645841246544e-324.
Can someone move for me?