Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F68D17D94 for ; Fri, 8 Jan 2016 12:39:16 +0000 (UTC) Received: (qmail 57982 invoked by uid 500); 8 Jan 2016 12:39:15 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 57953 invoked by uid 500); 8 Jan 2016 12:39:15 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 57943 invoked by uid 99); 8 Jan 2016 12:39:15 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2016 12:39:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 4C1B9C1BC9 for ; Fri, 8 Jan 2016 12:39:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.879 X-Spam-Level: ** X-Spam-Status: No, score=2.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id mNRLH3_BfbhO for ; Fri, 8 Jan 2016 12:39:14 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 8712D204D0 for ; Fri, 8 Jan 2016 12:39:13 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id u188so135423150wmu.1 for ; Fri, 08 Jan 2016 04:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=GLgFHtbS2zDyvVWDkEFQ/NspaGT471vKS121Kx8hfD0=; b=X6hX0y6XQ1NK0JKaTna7wzfqY1fWrG8FNrjKx0vNFHyoJ0A04VXcZ2kY+dbDEBaJB9 SDCfHTc8NX6WLvFUpx3pF8LOrNhnepnRAXMBTGwY4sEDFk+okWH3oI8RYu2KXgA6QOIK hnZ377al7uHMT9SzUpU8vJswM21aIezufSNAX4laUAVKQ1ZV1HI63rOd8UXChYIX2SZJ 0Ku+N/PWSxfMzmrHSJwkJb8Iix1kDwUFM86O0zN2H3iGiO4IS3UZtQlA0fAih26A+9aX 1EmM2AAmK+0k33PTF3g/WEl0eJKdAXinvqzfT0kF5++3pBacYTo58/+QPsvfanrrm25a z/Lg== X-Received: by 10.28.222.86 with SMTP id v83mr21595365wmg.17.1452256752345; Fri, 08 Jan 2016 04:39:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.43.132 with HTTP; Fri, 8 Jan 2016 04:38:42 -0800 (PST) In-Reply-To: References: From: Alessio Stalla Date: Fri, 8 Jan 2016 13:38:42 +0100 Message-ID: Subject: Re: Casting Double to BigDecimal To: users@groovy.apache.org Content-Type: multipart/alternative; boundary=001a114b1028d8a9ef0528d1df9e --001a114b1028d8a9ef0528d1df9e Content-Type: text/plain; charset=UTF-8 How do you verify that the two values are different? On 8 January 2016 at 13:34, Naresha K. wrote: > Value 1.9 will be of type BigDecimal. > Why are you using D? > > > On Fri, Jan 8, 2016 at 5:45 PM, Alberto Vilches wrote: > >> Hi everybody! We have an issue in our application, and we realized these >> two lines have differents results. We wonder why because we think it should >> calls to the DefaultGroovyMethods.asType(Number self, Class c). But it >> seems only the explicit call to "as" finally calls to the asType and the >> casting do a different thing (just a new BigDecimal(1.9D), but we wonder in >> which part of Groovy is happening) >> >> (BigDecimal)1.9D // >> "1.899999999999999911182158029987476766109466552734375" -> >> 1.9D as BigDecimal // "1.9" >> >> In fact, we tried to put these two lines in the Groovy console and see >> the AST in all the phases. But in all of them shows the same code: >> >> public java.lang.Object run() { >> ((1.9) as java.math.BigDecimal) >> return ((1.9) as java.math.BigDecimal) >> } >> >> Somebody please could give some light? Thank you very much and happy new >> year :) >> >> -- >> Un saludo. >> Alberto Vilches >> > > --001a114b1028d8a9ef0528d1df9e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
How do you verify that the two values are different?

On 8 January = 2016 at 13:34, Naresha K. <naresha.k@gmail.com> wrote:
=
Value 1.9 will be of type B= igDecimal.
Why are you using D?


On Fri, Jan 8, 2016 at 5:45 PM, Alberto Vilches <vilches@gmail.c= om> wrote:
Hi everybody! We have an issue in our application, and we realized these t= wo lines have differents results. We wonder why because we think it should = calls to the DefaultGroovyMethods.asType(Number self, Class<T> c). Bu= t it seems only the explicit call to "as" finally calls to the as= Type and the casting do a different thing (just a new BigDecimal(1.9D), but= we wonder in which part of Groovy is happening)

(B= igDecimal)1.9D =C2=A0// "1.8999999999999999111821580299874767661094665= 52734375" ->
1.9D as BigDecimal =C2=A0// "1.9"<= /div>

In fact, we tried to put these two lines in the Gr= oovy console and see the AST in all the phases. But in all of them shows th= e same code:

=C2=A0 =C2=A0public java.lang.Ob= ject run() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((1.9) as java.math.BigD= ecimal)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ((1.9) as java.math.Bi= gDecimal)
=C2=A0 =C2=A0 }

Some= body please could give some light? Thank you very much and happy new year := )

--
Un saludo.
Alberto Vilches


--001a114b1028d8a9ef0528d1df9e--