Re: Float to string and vice versa
From: Michael K. O'Neill (mikeathon2000_at_nospam.hotmail.com)
Date: 09/22/04
- Next message: Doug Harrison [MVP]: "Re: IMalloc::Alloc vs Malloc or new?"
- Previous message: Krzysztof Kozlowski: "Undo list menu"
- In reply to: Raed Sawalha: "Re: Float to string and vice versa"
- Next in thread: Ajay Kalra: "Re: Float to string and vice versa"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Sep 2004 08:05:51 -0700
There are an infinite number of values between .9999 and .99999 and with
float or double, there are only a finite number of choices to represent them
all.
So, you can never the precision with which numbers get represented.
Sometimes it's very good, sometimes it's not. A test like "if ( testedValue
== targetValue )..." is almost guaranteed to fail with floats or doubles.
Instead, you must do testing on acceptable error, such as "if ( abs(
testedValue-targetValue) <= .000001 )..." (or some other small number).
Mike
"Raed Sawalha" <raed_sawalha@hotmail.com> wrote in message
news:u2cMEqHoEHA.2340@TK2MSFTNGP10.phx.gbl...
> ok when i do this
> CString strComfortValue ;
>
> strComfortValue = objXml->GetChildData();
>
> //here strComfortValue = 0.9999
>
> float fComfortValue = atof(strComfortValue.GetString());
>
> //But the problem fComfortValue = 0.99989998
>
> WHY ? I need to get the same result of strComfortValue
>
>
>
> Regards
>
>
>
> "Sigurd Stenersen" <sigurds@utvikling.com> wrote in message
> news:u5PAnSHoEHA.868@TK2MSFTNGP10.phx.gbl...
> > Raed Sawalha wrote:
> > > Dear:
> > > Can I convert Float to string
> >
> > _ecvt(), _fcvt(), _gcvt() or sprintf()
> >
> > > and string to float like in integert
> > > (itoa)?
> >
> > atof() or sscanf()
> >
> >
> > --
> >
> >
> > Sigurd
> > http://utvikling.com
> >
> >
>
>
- Next message: Doug Harrison [MVP]: "Re: IMalloc::Alloc vs Malloc or new?"
- Previous message: Krzysztof Kozlowski: "Undo list menu"
- In reply to: Raed Sawalha: "Re: Float to string and vice versa"
- Next in thread: Ajay Kalra: "Re: Float to string and vice versa"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|