freemarker-notifications mailing list archives

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

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

minglaing ma updated FREEMARKER-102:
------------------------------------
    Description: 
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);
  

 

  was:
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|eclipse-javadoc:%E2%98%82=myfreemarker/D:%5C/Java%5C/jdk1.8.0_45_64%5C/jre%5C/lib%5C/rt.jar%3Cjava].[text|eclipse-javadoc:%E2%98%82=myfreemarker/D:%5C/Java%5C/jdk1.8.0_45_64%5C/jre%5C/lib%5C/rt.jar%3Cjava.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);
 

 


> ${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