Two bugs in UtilValidate.isDouble() and UtilValidate.isFloat()
-------------------------------------------------------------- Key: OFBIZ-2828 URL: https://issues.apache.org/jira/browse/OFBIZ-2828 Project: OFBiz Issue Type: Bug Components: framework Affects Versions: SVN trunk Reporter: Philipp Hoppen Priority: Minor Attachments: utilvalidate.txt There are two bugs in these two methods: First, the number of digits on the right of the decimal point is wrongly calculated: 1.2345 -> String of length 6, decimal point on index 1 the number of digits on the right of the decimal point is length - decimalPointIndex -1. The -1 was missing. The second bug is the following. If a String containing "1.00" is converted to a Double or Float (using Double.parseDouble() or Float.parseFloat()) and then converted back (using Double.toString() or Float.toString()) it will result in "1.0". if minDecimal was set to 2 (and the first bug was fixed) the methods will actually return false. I added some Unit-Tests to BaseUnitTests.java to express this in code. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. |
[ https://issues.apache.org/jira/browse/OFBIZ-2828?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Philipp Hoppen updated OFBIZ-2828: ---------------------------------- Attachment: utilvalidate.txt Patch for this problem, including Unit-Tests > Two bugs in UtilValidate.isDouble() and UtilValidate.isFloat() > -------------------------------------------------------------- > > Key: OFBIZ-2828 > URL: https://issues.apache.org/jira/browse/OFBIZ-2828 > Project: OFBiz > Issue Type: Bug > Components: framework > Affects Versions: SVN trunk > Reporter: Philipp Hoppen > Priority: Minor > Attachments: utilvalidate.txt > > > There are two bugs in these two methods: First, the number of digits on the right of the decimal point is wrongly calculated: > 1.2345 -> String of length 6, decimal point on index 1 > the number of digits on the right of the decimal point is length - decimalPointIndex -1. The -1 was missing. > The second bug is the following. If a String containing "1.00" is converted to a Double or Float (using Double.parseDouble() or Float.parseFloat()) and then converted back (using Double.toString() or Float.toString()) it will result in "1.0". if minDecimal was set to 2 (and the first bug was fixed) the methods will actually return false. > I added some Unit-Tests to BaseUnitTests.java to express this in code. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. |
In reply to this post by Nicolas Malin (Jira)
[ https://issues.apache.org/jira/browse/OFBIZ-2828?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jacques Le Roux closed OFBIZ-2828. ---------------------------------- Resolution: Fixed Fix Version/s: SVN trunk Release Branch 9.04 Assignee: Jacques Le Roux Thanks Philipp, Your patch is in trunk at r811793, R9.04 at r811794 > Two bugs in UtilValidate.isDouble() and UtilValidate.isFloat() > -------------------------------------------------------------- > > Key: OFBIZ-2828 > URL: https://issues.apache.org/jira/browse/OFBIZ-2828 > Project: OFBiz > Issue Type: Bug > Components: framework > Affects Versions: SVN trunk > Reporter: Philipp Hoppen > Assignee: Jacques Le Roux > Priority: Minor > Fix For: Release Branch 9.04, SVN trunk > > Attachments: utilvalidate.txt > > > There are two bugs in these two methods: First, the number of digits on the right of the decimal point is wrongly calculated: > 1.2345 -> String of length 6, decimal point on index 1 > the number of digits on the right of the decimal point is length - decimalPointIndex -1. The -1 was missing. > The second bug is the following. If a String containing "1.00" is converted to a Double or Float (using Double.parseDouble() or Float.parseFloat()) and then converted back (using Double.toString() or Float.toString()) it will result in "1.0". if minDecimal was set to 2 (and the first bug was fixed) the methods will actually return false. > I added some Unit-Tests to BaseUnitTests.java to express this in code. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. |
Free forum by Nabble | Edit this page |