在java中获取双数的小数部分的问题 [英] problem in getting the decimal part of a double number in java

查看:65
本文介绍了在java中获取双数的小数部分的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双号。


double n = 47758.35;

为了得到这个数字的小数部分我做了如下


long decPart =(long)((n-Math.floor(n))* 100);


在大多数情况下,我得到正确的小数部分,但在这种情况下,decPart变为 34 QUOT;而不是35


我怎样才能得到确切的小数部分


请帮助

解决方案


我有一个双号。


double n = 47758.35;

为了得到这个数字的小数部分我做了如下


long decPart =(long)((n-Math.floor(n))* 100);


在大多数情况下,我得到正确的小数部分,但在这种情况下,decPart变为 34 QUOT;而不是35


我怎么能得到确切的小数部分


请帮助



您可以将其拆分为字符串

展开 | 选择 | Wrap | 行号



您可以将其拆分为字符串

展开 | 选择 | Wrap | 行号


< blockquote class =post_quotes>
Im gettinf nums as spilting后为空字符串

即如果n = 2345.65则s =" 2345.65"

但是nums变成[]

所以不能拿nums [1] ......

exception arrayindexoutofbound



使用

展开 | 选择 | Wrap | 行号


Ive got a double number.

double n=47758.35;
Inorder to get the decimal part of this number i did as follows

long decPart = (long) ((n-Math.floor(n))*100);

in most cases i get the correct decimal part but in this case the decPart becomes"34" instead of "35"

how can i get the exact decimal part

Please Help

解决方案

Ive got a double number.

double n=47758.35;
Inorder to get the decimal part of this number i did as follows

long decPart = (long) ((n-Math.floor(n))*100);

in most cases i get the correct decimal part but in this case the decPart becomes"34" instead of "35"

how can i get the exact decimal part

Please Help

You can split it up as string

Expand|Select|Wrap|Line Numbers


You can split it up as string

Expand|Select|Wrap|Line Numbers


Im gettinf nums as empty string after spilting
ie if n=2345.65 then s="2345.65"
but nums becomes []
so cant take nums[1]......
exception arrayindexoutofbound

Use

Expand|Select|Wrap|Line Numbers


这篇关于在java中获取双数的小数部分的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆