如何在JSP / Java中从double获得全部和分数部分?如果值为3.25,那么我想得到fractional =.25,whole = 3
fractional =.25
whole = 3
我们如何用Java做到这一点?
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