freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (FREEMARKER-102) ${float?string('0.##;; roundingMode=halfUp')}
Date Wed, 08 Aug 2018 15:35:00 GMT

     [ https://issues.apache.org/jira/browse/FREEMARKER-102?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Daniel Dekany closed FREEMARKER-102.
------------------------------------
    Resolution: Not A Bug

> ${float?string('0.##;; roundingMode=halfUp')}
> ---------------------------------------------
>
>                 Key: FREEMARKER-102
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-102
>             Project: Apache Freemarker
>          Issue Type: Bug
>    Affects Versions: 2.3.28
>            Reporter: minglaing ma
>            Priority: Major
>   Original Estimate: 12h
>  Remaining Estimate: 12h
>
> java
> Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
>  configuration.setClassForTemplateLoading(new Main().getClass(), "/jigndu");
>  Template template = configuration.getTemplate("index.ftl");
> Map<Object,Object> root =new HashMap<Object, Object>();
>  root.put("float", 172.525f);
>  Writer out =new OutputStreamWriter(System.out);
>  template.process(root, out);
>  
> ftl
> ${float?string('0.##;; roundingMode=halfUp')}
>  
> output
> 172.52
>  
> I think 172.53 is right
>  
> the reason is 
> java.text.NumberFormat  format method   param is a double,now i use a float。
>  when float to double wrong,i  think
>   
>  freemarker.core.JavaTemplateNumberFormat.format  method should
>   
>  if (number instanceof Float)
> { return javaNumberFormat.format(new BigDecimal(String.valueOf(number))); }
> return javaNumberFormat.format(number);
>   
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message