allen501pc / jlibs

Automatically exported from code.google.com/p/jlibs
0 stars 0 forks source link

applyDigits in XSInstance fails on small numbers #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
String.valueOf( double ) has as format [0-9]+(.[0-9]+(E(-|+)[0-9]+)?)?
However, applyDigits in XSInstance assumes it is only number.fraction.
Consequently on small numbers like 0.000005678
which has a string representation 5.678E-6 the algorithm fails.

See the test below:
==============================================
package nl.esi.xsi;

import static org.junit.Assert.*;

import org.junit.Test;

public class ToDigit {

    @Test
    public void test() {
           double obj = 0.000005678;
           System.out.println("obj = "+ obj);

           String str = String.valueOf(obj);
           System.out.println("str = " +str);

           String number, fraction;
        int dot = str.indexOf(".");
        if(dot==-1){
            number = str;
            fraction = "";
        }else{
            number = str.substring(0, dot);
            fraction = str.substring(dot+1);
        }

        assertEquals("0", number);
        assertEquals("000005678", fraction);
    }   
}

Original issue reported on code.google.com by Pierre.v...@gmail.com on 20 Nov 2013 at 3:55

GoogleCodeExporter commented 9 years ago
Fixed in r1776

the new build is available in maven snapshots repository
alternatively, you can download it from:
https://dl.dropboxusercontent.com/u/326301/jlibs-r1776.zip

Original comment by santhosh.tekuri@gmail.com on 29 Nov 2013 at 11:30