import java.text.*;
public class TY
{
public static void main(String[] args)
{
double per=3.9898;
DecimalFormat df=new DecimalFormat("##.00");
double pp=per/4;
System.out.println(pp);
System.out.println(pp*100);
System.out.println(df.format(per*100/4)+"%");
}
}
public class TY
{
public static void main(String[] args)
{
double per=3.9898;
DecimalFormat df=new DecimalFormat("##.00");
double pp=per/4;
System.out.println(pp);
System.out.println(pp*100);
System.out.println(df.format(per*100/4)+"%");
}
}
解决方案 »
- 用Future实现Timeout,Call方法已经返回,但Future.get方法没有得到,而出了timeoutException
- 怎样用javase代码播放视频
- [j2se]访问控制修饰符protected疑问[孙卫琴原书代码]
- java游戏的问题
- The import javax.media cannot be resolved 请问如何解决?
- 急求JAVA自定义打印页面问题?
- 迷惑中``问一个关于变量声明的问题(在线等待,立刻给分)
- helloworld.class到哪里去了?
- 如何判断!
- 各位大哥,请帮个忙!!!
- 请教“后台线程”
- 在java中怎么把Date类型对象转换成Calendar类型的对象
如果想得到准确的精度,使用BigDecimal类。
public class TY
{
public static void main(String[] args)
{
float per=3.9898f;
DecimalFormat df=new DecimalFormat("##.00");
float pp=per/4;
System.out.println(pp);
System.out.println(pp*100);
System.out.println(df.format(per*100/4)+"%");
}
}
虽然是Double,在计算机里的计算器存储了64位长的数据.具体的算法可以去看看操作系统.
不过这个问题不影响编程的精度吧.
应该是浮点型的精度问题。
如果想得到准确的精度,使用BigDecimal类。
同意!
能否举个例子
BigDecimal big1 = new BigDecimal("3.9898");
BigDecimal result = big1.divide(new BigDecimal("4"));
System.out.println(result.toString());
result = result.multiply(new BigDecimal("100"));
System.out.printf("%.2f%%%n", result);