如何在 JSP/Java 中从 double 获得完整部分和分数部分?
如何在JSP / Java中从双倍获得整体和分数部分?如果值为3.25,那么我想得到,fractional =.25
whole = 3
我们如何在Java中做到这一点?
如何在JSP / Java中从双倍获得整体和分数部分?如果值为3.25,那么我想得到,fractional =.25
whole = 3
我们如何在Java中做到这一点?
double value = 3.25;
double fractionalPart = value % 1;
double integralPart = value - fractionalPart;
http://www.java2s.com/Code/Java/Data-Type/Obtainingtheintegerandfractionalparts.htm
double num;
long iPart;
double fPart;
// Get user input
num = 2.3d;
iPart = (long) num;
fPart = num - iPart;
System.out.println("Integer part = " + iPart);
System.out.println("Fractional part = " + fPart);
输出:
Integer part = 2
Fractional part = 0.2999999999999998