Menu

#1956 DecimalBox error formatting , and . (loss the scale!!)

5.0.1
closed-fixed
nobody
5
2010-04-26
2010-04-16
No

post 1)
in Decimalbox when I get the value myDecimalbox.getValue() loss the scale (I use 3 decimals) and the scale remains in "0" and when if try to save a value of 123.456 ( myVar = myDecimalbox.getvalue() ) I obtain 123456

post 2)
the error is in toNumberOnly(value)

my value is 44.553 and toNumberOnly set a scale of "0" (the scale is "3")

the error is when i don't touch the decimalbox...

protected Object coerceFromString(String value) throws WrongValueException {
final Object[] vals = toNumberOnly(value);
final String val = (String)vals[0];
if (val == null || val.length() == 0)
return null;

try {
BigDecimal v = new BigDecimal(val);
if (_scale != AUTO)
v = v.setScale(_scale, getRoundingMode());

int divscale = vals[1] != null ? ((Integer)vals[1]).intValue(): 0;
if (divscale > 0) {
final BigDecimal ten = new BigDecimal(10);
do {
v = v.divide(ten, _scale == AUTO ? v.scale()+1: _scale,

or maybe the error is in the file: InputElement.java

-->> same = Objects.equals(_value, val);
_value = 44.553
val = 44553

obviously not same, but i'dont change it

public void setText(String value) throws WrongValueException {
if (_maxlength > 0 && value != null && value.length() > _maxlength)
throw showCustomError(
new WrongValueException(this, MZul.STRING_TOO_LONG, new Integer(_maxlength)));

final Object val = coerceFromString(value);
final boolean same = Objects.equals(_value, val);
boolean errFound = false;
if (!same || !_valided || _errmsg != null) { //note: the first time (!_valided) must always validate
validate(val); //Bug 2946917: don't validate if not changed

errFound = _errmsg != null;
clearErrorMessage(); //no error at all
}

post 3)
my number is formatted like this: 149,50

if I modify the number (Decimalbox), not problem.

if I don't modify the number, when I get the value arcostoult.getValue() this value change for 14950

the problem I think is the "," like decimal...

then, the error is in toNumberOnly(value)

Discussion

  • Jumper Chen

    Jumper Chen - 2010-04-20

    Could you please upload a runnable example to show up your problem.

     
  • Jumper Chen

    Jumper Chen - 2010-04-20
    • status: open --> pending
     
  • Pedro Gonzalez

    Pedro Gonzalez - 2010-04-20

    A zk runnable example:

    <?page title="Auto Generated index.zul"?>
    <zk>
    <zscript><![CDATA[

    String valore = execution.getParameter("valore");
    if (valore==null || valore.isEmpty() ){
    myValue = new java.math.BigDecimal("123.54");
    }else{
    myValue = new java.math.BigDecimal(valore);
    }
    ]]>
    </zscript>

    <window title="Decimal error" border="normal" width="300px">
    <separator></separator>
    <label>Try to write 4.51 and click the button (the value changes to 451,000)</label>
    <separator></separator>
    <label>If you write 4,51 there is not a problem</label>
    <separator></separator>
    <separator></separator>
    <decimalbox id="myDecimalBox" value="${myValue}" cols="10" maxlength="9" format="#,##0.000" />
    <button label="Click" onClick="myFunction();" />
    <zscript><![CDATA[

    void myFunction(){
    java.math.BigDecimal val = myDecimalBox.getValue();

    Executions.sendRedirect("/index.zul?valore="+val.toString());
    }
    ]]>
    </zscript>
    </window>
    </zk>

     
  • Pedro Gonzalez

    Pedro Gonzalez - 2010-04-20
    • status: pending --> open
     
  • Jumper Chen

    Jumper Chen - 2010-04-26

    Fixed since 2010/04/26.

     
  • Jumper Chen

    Jumper Chen - 2010-04-26
    • labels: 1167398 --> Components
    • status: open --> closed-fixed
     

Log in to post a comment.