应该是一个简单的.我最初会在javascript中执行此操作,但必须在设置到我的处理程序页面中的表单之前执行此操作.无论如何,我需要使这些值有2位小数.例如,219333.5888888需要219333.58.是否有修剪功能?
form.setUnitRepairCost(Double.toString(jobPlanBean.getUnitTotalCost())); //UNIT REPAIR COST
form.setUnitMaterialCost(Double.toString(jobPlanBean.getUnitTotalMaterialCost())); //UNIT MATERIAL COST
Run Code Online (Sandbox Code Playgroud)
Pra*_*tik 49
这是格式化十进制值的简单示例
import java.text.*;
public class DecimalPlaces {
public static void main(String[] args) {
double d = 1.234567;
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(d));
}
}
Run Code Online (Sandbox Code Playgroud)
hur*_*own 12
public static void main(String[] args) {
double d = 6.3546;
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(d));
}
Run Code Online (Sandbox Code Playgroud)
获得双后卫而不是字符串:
double d = 80.123;
DecimalFormat df = new DecimalFormat("#.##");
double p = Double.parseDouble(df.format(d));
Run Code Online (Sandbox Code Playgroud)
小智 6
将double乘以100.0并将其强制转换为int,然后将int强制将其强制转换为double并除以100.0
int temp = (int)(longDouble*100.0);
double shortDouble = ((double)temp)/100.0;
Run Code Online (Sandbox Code Playgroud)
怎么样:
new java.text.DecimalFormat("0.00").format( yourNumber );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
78539 次 |
| 最近记录: |