Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 79497 invoked from network); 15 Sep 2005 16:08:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Sep 2005 16:08:51 -0000 Received: (qmail 32191 invoked by uid 500); 15 Sep 2005 16:08:47 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 32117 invoked by uid 500); 15 Sep 2005 16:08:47 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 32104 invoked by uid 99); 15 Sep 2005 16:08:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Sep 2005 09:08:47 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mattom@gmx.at designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 15 Sep 2005 09:08:56 -0700 Received: (qmail invoked by alias); 15 Sep 2005 16:08:43 -0000 Received: from mail.aim-ag.com (EHLO [10.0.1.8]) [193.154.31.84] by mail.gmx.net (mp014) with SMTP; 15 Sep 2005 18:08:43 +0200 X-Authenticated: #7708740 Message-ID: <43299C93.5060907@gmx.at> Date: Thu, 15 Sep 2005 18:08:51 +0200 From: Thomas Lutz User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050727) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: [CForms] Bug when converting Doubles and BigDecimals... Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi list ! Starting with http://www.mail-archive.com/users@cocoon.apache.org/msg29109.html from the users list I found a bug (at least I think it is one) in the FormattingDecimalConvertor.java. Setup (code snippets below): -a form with a field widget that has a datatype decimal (and some formatting to make it look pretty) -a binding that converts from the xml to a decimal -display the form enter something like: 12345678901234567890123456789012345678901234567890 -this number is rejected by database validation, because it's to large -redisplay the form, and, the orginal submitted value has been rounded by the convertor to something like 1.2345E60 because -> in FormattingDecimalConvertor.java the line decimalFormat.setParseBigDecimal(true); is missing. So decimalFormat.parse(value) returns a double, and no BigDecimal, which results in "loosing accuracy". Another thing that could be optimized is that decimalFormat.parse(value) is used, and not decimalFormat.parse(value,ParsePosition). If the ParsePosition would be compared with the length of value, you could be sure that e.g. trailing alphachars would cause an error. So IMHO something like: value = value.replace(' ', (char)160); DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache); decimalFormat.setParseBigDecimal(true); // NEW Number decimalValue; ParsePosition parsePosition = new ParsePosition( 0 ); decimalValue = decimalFormat.parse(value, parsePosition); // NEW ask for error index and compare lenght instead of catching the parsing exception if ( ( parsePosition.getErrorIndex() != -1 ) || ( parsePosition.getIndex() != value.length() ) ) { return ConversionResult.create("decimal"); } would be better. Shall I supply a patch ? Which other classes should I have a look at ? regards, Tom Code snippets: Form definition: praemieNtoVtg #.00 Form binding: