double doub = 543.345671; '
int num1 = (int) doub; //543
int num2 = getNumAfterDecimal(doub-num1); //return 345671
我需要小数部分到整数。
狐的传说
浏览 195回答 5
5回答
慕无忌1623718
用于将 映射到 :,然后 用于获取作为 s 的不同部分。然后,(可选)将这些值解析为 s:Double.toString()doubleStringDouble.toString(doub)String.split("\\.")StringInteger.valueOf()Integerdouble doub = 543.345671;// Here, you want to split the String on character '.'// As String.split() takes a regex, the dot must be escaped. String[] parts = Double.toString(doub).split("\\.");System.out.println(Integer.valueOf(parts[0]));System.out.println(Integer.valueOf(parts[1]));输出:543345671
这取决于你想要的小数点后有多少位,但这是要点:double d = doub - (int)doub; // will give you 0.xyzint result = d * 1000; // this is for 3 digits, the number of zeros in the multiplier decides the number of digits