如何找出一个数字有多少个小数? [英] How to find out how many decimals a number has?

查看:74
本文介绍了如何找出一个数字有多少个小数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何验证Java中的数字有多少个小数位?

How can I verify how many decimals a number has in Java?

我需要将PI计算为一定的小数位数,并且我想知道达到所需的小数位数后如何停止循环吗?

I need to calculate PI to a certain number of decimal, and I want to know how I can stop my loop when I reach the desired decimals number?

推荐答案

您不能直接检查 double 上的小数位数,但可以将其转换为 String 使用 String str = number +"; ,然后检查 str.length .

You can't check the number of decimals on a double directly, but you can convert it to a String using String str = number + ""; and then check str.length.

这篇关于如何找出一个数字有多少个小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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