I don't think a java.util.regex solution would be hugely more complicated. One advantage is that all it expects is the string datavalue. If casting to a double you might also need to catch a class caste exception to be on the safe side. ie you have to ask is it a double first before you can ask is that double = zero.
Cheers Bob 2010/1/26 Trí Trần Thanh <tranthanhtr...@gmail.com> > Hi all, my way is easy and simple. Cast to Double and compare with new > Double(0). new Double(value).equal(new Double(0)) ? how do you think? > > On 1/26/10, Bob Jolliffe <bobjolli...@gmail.com> wrote: > > 2010/1/26 Lars Helge Øverland <larshe...@gmail.com> > > > >> > >> > >> 2010/1/26 Trí Trần Thanh <tranthanhtr...@gmail.com> > >> > >> > >>> ================================ > >>> Tran Thanh Tri > >>> HISP Viet Nam > >>> Cell phone: +84903670967 > >>> Website: http://tringuyenvn.com > >>> ================================ > >>> > >>> > >>> 2010/1/25 <nore...@launchpad.net> > >>> > >>>> ------------------------------------------------------------ > >>>> revno: 1337 > >>>> committer: Lars Helge Oeverland <larshe...@gmail.com> > >>>> branch nick: trunk > >>>> timestamp: Mon 2010-01-25 15:30:51 +0100 > >>>> message: > >>>> Improved DataValue.isZero > >>>> modified: > >>>> dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java > >>>> > >>>> > >>>> -- > >>>> lp:dhis2 > >>>> https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk<https://code.launchpad.net/%7Edhis2-devs-core/dhis2/trunk> > <https://code.launchpad.net/%7Edhis2-devs-core/dhis2/trunk> > >>>> > >>>> Your team DHIS 2 developers is subscribed to branch lp:dhis2. > >>>> To unsubscribe from this branch go to > >>>> > https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription<https://code.launchpad.net/%7Edhis2-devs-core/dhis2/trunk/+edit-subscription> > < > https://code.launchpad.net/%7Edhis2-devs-core/dhis2/trunk/+edit-subscription > > > >>>> . > >>>> > >>>> === modified file > >>>> 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java' > >>>> --- > dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java > >>>> 2010-01-25 14:08:24 +0000 > >>>> +++ > dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java > >>>> 2010-01-25 14:30:51 +0000 > >>>> @@ -198,7 +198,7 @@ > >>>> public boolean isZero() > >>>> { > >>>> return dataElement != null && dataElement.getType().equals( > >>>> DataElement.VALUE_TYPE_INT ) > >>>> - && value != null && ( value.equals( "0" ) || > >>>> value.startsWith( "0." ) ); > >>>> > >>> This script will not working fine. *new Double("0.001").intValue()==0 > is > >>> true but it must be false.* > >>> I thing it must be n*ew Double(value)==(new Double(0))* > >>> what do you thing ? > >>> > >>> + && value != null && new Double( value ).i > >>> > >>> > >> I don't think we should allow decimal numbers in the first place, eg it > >> cant be 0.5 people with malaria or vaccines given. But Jason pointed out > >> that regex might be the better solution for this in any case. > >> > > > > Maybe something like > > > > ^[0]*[.]?[0]*$ > > > > Start word. Read any number of zeroes followed optionally by a '.' > followed > > by any number of zeroes. End word. > > > > From my emacs buffer, M indicates a match > > 0 M > > 003 > > 0.00 M > > 0.03 > > .000 M > > 00.0 M > > 008000 > > > > Cheers > > Bob > > > > Feel free to improve, I don't have strong opinions on this. > >> > >> > >> > >> > >> _______________________________________________ > >> Mailing list: > >> https://launchpad.net/~dhis2-devs <https://launchpad.net/%7Edhis2-devs> > <https://launchpad.net/%7Edhis2-devs> > >> Post to : dhis2-devs@lists.launchpad.net > >> Unsubscribe : > >> https://launchpad.net/~dhis2-devs <https://launchpad.net/%7Edhis2-devs> > <https://launchpad.net/%7Edhis2-devs> > >> More help : https://help.launchpad.net/ListHelp > >> > >> > > > > -- > Sent from my mobile device > > ================================ > Tran Thanh Tri > HISP Viet Nam > Cell phone: +84903670967 > Website: http://tringuyenvn.com > ================================ >
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp