Struts 1.2 降低 <bean:write> 标签中的浮点精度
Struts 1.2 decrease float precision in <bean:write> tag
我的 jsp 中有以下代码:
<bean:write name="contract" property="percentage"/>
属性百分比returns一个浮点数。
我的问题是我需要将浮点数的精度(仅用于显示)降低到 3 位小数,如 System.out.printf("%.3f", value);
如何在我的 bean:write 标签中做到这一点?
提前致谢。
我找到了解决方案,我刚刚发现了格式属性:
<bean:write name="contract" property="percentage" format="###.###"/>
抱歉给您带来不便。
我可以向您建议一些非常简单的解决方法。创建一个 getter 方法,例如 percentagePrecission 到 return 您想要的浮点数精度。
例如:
public class YourClass{
public float percentage;
//getters, setters and other properties
public String percentagePrecision(){
return percentage's precision
}
}
我的 jsp 中有以下代码:
<bean:write name="contract" property="percentage"/>
属性百分比returns一个浮点数。
我的问题是我需要将浮点数的精度(仅用于显示)降低到 3 位小数,如 System.out.printf("%.3f", value);
如何在我的 bean:write 标签中做到这一点?
提前致谢。
我找到了解决方案,我刚刚发现了格式属性:
<bean:write name="contract" property="percentage" format="###.###"/>
抱歉给您带来不便。
我可以向您建议一些非常简单的解决方法。创建一个 getter 方法,例如 percentagePrecission 到 return 您想要的浮点数精度。
例如:
public class YourClass{
public float percentage;
//getters, setters and other properties
public String percentagePrecision(){
return percentage's precision
}
}