java - How to pass a BigDecimal to a custom taglib (WebSphere) -


i have custom taglib try give bigdecimal to, scale isn't kept. seems bigdecimal converted double, bigdecimal. bug in websphere? or missing something?

my controller (i'm using spring):

@controller @requestmapping("/bigdecimaltest") public class bigdecimaltestcontroller {      @requestmapping     public string display(final map<string, object> model) {         model.put("bigdecimal", new bigdecimal("126.58"));         return "bigdecimaltest";     }  } 

my jsp:

<%@taglib uri="/custom-taglibs/bigdecimal.tld" prefix="bd"%> <!doctype html public "-//w3c//dtd html 4.01//en"         "http://www.w3.org/tr/html4/strict.dtd"> <html> <head>   <title>bigdecimal test</title> </head> <body> <bd:display value="${bigdecimal}"/> </body> </html> 

my taglib descriptor:

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"     version="2.0">   <description>bigdecimal test</description>   <tlib-version>1.0</tlib-version>   <short-name>bd</short-name>   <tag>     <description>display informations bigdecimal</description>     <name>display</name>     <tag-class>bigdecimaldisplay</tag-class>     <body-content>empty</body-content>     <attribute>       <name>value</name>       <required>true</required>       <rtexprvalue>true</rtexprvalue>       <type>java.math.bigdecimal</type>     </attribute>   </tag> </taglib> 

my tag class:

public class bigdecimaldisplay extends tagsupport {      private static final long serialversionuid = 2049900195699675393l;      private bigdecimal value;      public void setvalue(final bigdecimal value) {         this.value = value;     }      @override     public int dostarttag() throws jspexception {         final jspwriter out = pagecontext.getout();         try {             out.print("<div>");             out.print("<div>value: ");             out.print(value.toplainstring());             out.print("</div>");             out.print("<div>scale: ");             out.print(value.scale());             out.print("</div>");             out.print("</div>");         } catch (final ioexception e) {             throw new jspexception(e);         }         return skip_body;     }  } 

expected output:

value: 126.58
scale: 2

actual output:

value: 126.5799999999999982946974341757595539093017578125
scale: 46

edit: able reproduce issue without using spring. since obourgain not reproduce on jetty, seems websphere bug.

edit: ibm bug pm48569?

mr. can make patern if know how many decimals want. link: http://docs.oracle.com/javase/1.4.2/docs/api/java/text/decimalformat.html hope you. gr. gilian


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -