Jothi
Jothi

Reputation: 15110

Text box showing value as 3.2543254E7.How to avoid it and show as 325432547 in struts

I am using struts2 for my application. I entered value as 325432547. In Edit mode value shows as 3.2543254E7. In text box to avoid it?

<s:textfield name="lstVehicleAttendance(%{#attr.row_rowNum-1}).closingTime"
id="closingTime" maxlength="20" size="20" value="%{#attr.row.closingTime}">
</s:textfield>

Upvotes: 0

Views: 1067

Answers (2)

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

Your problem is not related to the Struts2.Your question still needs a lot of inputs to decide what exactly is the issue.

  1. How you calculating the number?
  2. Where you displaying it?
  3. What you mean by Edit mode?

I assume that the issue might be coming when you are dealing with double/floating number.A double number can only store a certain amount of significant digits (with a decimal dot somewhere).

for example if i run this simple program in my editor

public static void main(String[] args) {
        double val=999999999.999999d;
        System.out.println(val);

    }

Output is 9.99999999999999E8 so either you need some sort of NumberFormat

else use Struts2 Number formatting facility as it will also use same Java's built-in formatting features formatting-dates-and-numbers

Upvotes: 0

Prashant Bhate
Prashant Bhate

Reputation: 11087

You might want to define following in default properties

format.number = {0,number,#0.0##}

And call getText(...) from s:textfield

<s:textfield key="orderItem.price" 
             value="%{getText('format.number',{'orderItem.price'})}" />

See http://struts.apache.org/2.0.14/docs/formatting-dates-and-numbers.html for more details

Upvotes: 1

Related Questions