简体   繁体   English

浮点型值以科学计数法显示

[英]Float type value is showing in scientific notation

The MMCHAM8 value is 0.0005 and it's data type is float but in screen it is showing scientific notation value like 5.0E-4 MMCHAM8值为0.0005 ,数据类型为float,但在屏幕上显示的科学计数值为5.0E-4

<td>
    <input size="5" type="text" name="MMCHAM8" id="MMCHAM8" 
           readonly="readonly" ondblclick="alert(this.value)" 
           class="readonly_field"
           value="${mat.mmValues.MMCHAM8}" />
</td>`

This isn't hexdecimal, it's scientific notation . 这不是十六进制,而是科学计数法 5.0E-4 means 5 * 10 -4 , which is of course equal 0.0005. 5.0E-4表示5 * 10 -4 ,当然等于0.0005。

If you want it displayed differently, you could use DecimalFormat : 如果希望以其他方式显示它,则可以使用DecimalFormat

DecimalFormat df = new DecimalFormat("#.####");
String formatted = df.format(mat.mmValues.MMCHAM8);

(and just echo formatted in your JSP page) (只是在您的JSP页面中设置了回声formatted

There are many options on how to do it> 有很多选择方法>

  1. use DecimalFormat : 使用DecimalFormat

     NumberFormat f = new DecimalFormat("#.0000"); f.format(mat.mmValues.MMCHAM8); 
  2. use String.format() : 使用String.format()

     String.format("%.4f", mat.mmValues.MMCHAM8) 
  3. use JSTL build in functionality: 使用JSTL内置功能:

     <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <fmt:formatNumber type="number" maxFractionDigits="4" value="${mat.mmValues.MMCHAM8}" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM