You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by BOUTERFASS Mostapha <mo...@gmail.com> on 2009/02/06 17:28:59 UTC
Float precison
Hi all
i put in my context 3 float : v1 = 2 v2 = 11 v3 = 0.1
in my template i have
#set( $mnt = (100 * v1 * v2 / (1 + v3)))
v1 = $v1
v2 = $v2
v3 = $v3
mnt = $mnt
after execution i have this result
v1 = 2.0
v2 = 11.0
v3 = 0.1
mnt = 1999.9999999999998
but the right result mast be mnt = 2000 !!!
how can i resolve this problem
thanx in advence
and sorry for mu english
Re: Float precison
Posted by BOUTERFASS Mostapha <mo...@gmail.com>.
thanx a lot or your help
On Fri, Feb 6, 2009 at 5:05 PM, Nathan Bubna <nb...@gmail.com> wrote:
> You could use the MathTool to round your result:
>
>
> http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/MathTool.html
>
> You might also try consider using Float or BigDecimal types instead of
> Double.
>
> On Fri, Feb 6, 2009 at 8:28 AM, BOUTERFASS Mostapha
> <mo...@gmail.com> wrote:
> > Hi all
> > i put in my context 3 float : v1 = 2 v2 = 11 v3 = 0.1
> >
> > in my template i have
> >
> > #set( $mnt = (100 * v1 * v2 / (1 + v3)))
> > v1 = $v1
> > v2 = $v2
> > v3 = $v3
> > mnt = $mnt
> >
> >
> > after execution i have this result
> > v1 = 2.0
> > v2 = 11.0
> > v3 = 0.1
> > mnt = 1999.9999999999998
> >
> >
> > but the right result mast be mnt = 2000 !!!
> >
> >
> > how can i resolve this problem
> >
> >
> > thanx in advence
> > and sorry for mu english
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
> For additional commands, e-mail: dev-help@velocity.apache.org
>
>
Re: Float precison
Posted by Nathan Bubna <nb...@gmail.com>.
You could use the MathTool to round your result:
http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/MathTool.html
You might also try consider using Float or BigDecimal types instead of Double.
On Fri, Feb 6, 2009 at 8:28 AM, BOUTERFASS Mostapha
<mo...@gmail.com> wrote:
> Hi all
> i put in my context 3 float : v1 = 2 v2 = 11 v3 = 0.1
>
> in my template i have
>
> #set( $mnt = (100 * v1 * v2 / (1 + v3)))
> v1 = $v1
> v2 = $v2
> v3 = $v3
> mnt = $mnt
>
>
> after execution i have this result
> v1 = 2.0
> v2 = 11.0
> v3 = 0.1
> mnt = 1999.9999999999998
>
>
> but the right result mast be mnt = 2000 !!!
>
>
> how can i resolve this problem
>
>
> thanx in advence
> and sorry for mu english
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org
Re: Float precison
Posted by Leon sdh5724 <sd...@gmail.com>.
Here $mnt display is right. It is not velocity problem. It is a float
problem, you can found it in IEEE float part spec document.
You can test you code in JAVA class, "mnt" value alse will display as
1999.9999....
If you use float, you shuold permit float inaccuracy.
2009/2/7 BOUTERFASS Mostapha <mo...@gmail.com>
> Hi all
> i put in my context 3 float : v1 = 2 v2 = 11 v3 = 0.1
>
> in my template i have
>
> #set( $mnt = (100 * v1 * v2 / (1 + v3)))
> v1 = $v1
> v2 = $v2
> v3 = $v3
> mnt = $mnt
>
>
> after execution i have this result
> v1 = 2.0
> v2 = 11.0
> v3 = 0.1
> mnt = 1999.9999999999998
>
>
> but the right result mast be mnt = 2000 !!!
>
>
> how can i resolve this problem
>
>
> thanx in advence
> and sorry for mu english
>