Error rounding float value with Zend_Locale_Format::toNumber()

7 messages Options
Embed this post
Permalink
umpirsky

Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Hi.

I tried to round 98.99999625 value with Zend_Locale_Format::toNumber() and I get result 98, I expected 99.00.

I've just added new issue http://framework.zend.com/issues/browse/ZF-7170. Do you think I'm wrong somewhere in my code?

Regards,
Sasa Stamenkovic.
thomasW

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Shouldn't you use toFloat when you want to have a float value ?

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "umpirsky" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, July 01, 2009 4:04 PM
Subject: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()


>
> Hi.
>
> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber() and
> I
> get result 98, I expected 99.00.
>
> I've just added new issue http://framework.zend.com/issues/browse/ZF-7170.
> Do you think I'm wrong somewhere in my code?
>
> Regards,
> Sasa Stamenkovic.
> --
> View this message in context:
> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
> Sent from the Zend Framework mailing list archive at Nabble.com.

umpirsky

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Hm, maybe, but what is precision for in toNumber method then? And why it works for most cases and not for this particular one?

Regards,
Sasa Stamenkovic.

thomasW wrote:
Shouldn't you use toFloat when you want to have a float value ?

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "umpirsky" <umpirsky@gmail.com>
To: <fw-general@lists.zend.com>
Sent: Wednesday, July 01, 2009 4:04 PM
Subject: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()


>
> Hi.
>
> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber() and
> I
> get result 98, I expected 99.00.
>
> I've just added new issue http://framework.zend.com/issues/browse/ZF-7170.
> Do you think I'm wrong somewhere in my code?
>
> Regards,
> Sasa Stamenkovic.
> --
> View this message in context:
> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
thomasW

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
It's the same reason as for toFloat().

But the used number format is different for each of the functions.
toInteger(), toFloat() and toNumber() all define different formats and
therefor they all handle number differently. When this would not be the
case, then there would have been no reason to create 3 methods. :-)

You could get the same result within toNumber() when you define that the
number format has to be rounded instead of truncated.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com


----- Original Message -----
From: "umpirsky" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, July 01, 2009 6:18 PM
Subject: Re: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()


>
> Hm, maybe, but what is precision for in toNumber method then? And why it
> works for most cases and not for this particular one?
>
> Regards,
> Sasa Stamenkovic.
>
>
> thomasW wrote:
>>
>> Shouldn't you use toFloat when you want to have a float value ?
>>
>> Greetings
>> Thomas Weidner, I18N Team Leader, Zend Framework
>> http://www.thomasweidner.com
>>
>> ----- Original Message -----
>> From: "umpirsky" <[hidden email]>
>> To: <[hidden email]>
>> Sent: Wednesday, July 01, 2009 4:04 PM
>> Subject: [fw-general] Error rounding float value with
>> Zend_Locale_Format::toNumber()
>>
>>
>>>
>>> Hi.
>>>
>>> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber()
>>> and
>>> I
>>> get result 98, I expected 99.00.
>>>
>>> I've just added new issue
>>> http://framework.zend.com/issues/browse/ZF-7170.
>>> Do you think I'm wrong somewhere in my code?
>>>
>>> Regards,
>>> Sasa Stamenkovic.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24292705.html
> Sent from the Zend Framework mailing list archive at Nabble.com.

umpirsky

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Yes, with toFloat() I get string(5) "99.00", but I wanted to have string(5) "99,00" when using sv_SE locale.

Regards,
Saša Stamenković

thomasW wrote:
It's the same reason as for toFloat().

But the used number format is different for each of the functions.
toInteger(), toFloat() and toNumber() all define different formats and
therefor they all handle number differently. When this would not be the
case, then there would have been no reason to create 3 methods. :-)

You could get the same result within toNumber() when you define that the
number format has to be rounded instead of truncated.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com


----- Original Message -----
From: "umpirsky" <umpirsky@gmail.com>
To: <fw-general@lists.zend.com>
Sent: Wednesday, July 01, 2009 6:18 PM
Subject: Re: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()


>
> Hm, maybe, but what is precision for in toNumber method then? And why it
> works for most cases and not for this particular one?
>
> Regards,
> Sasa Stamenkovic.
>
>
> thomasW wrote:
>>
>> Shouldn't you use toFloat when you want to have a float value ?
>>
>> Greetings
>> Thomas Weidner, I18N Team Leader, Zend Framework
>> http://www.thomasweidner.com
>>
>> ----- Original Message -----
>> From: "umpirsky" <umpirsky@gmail.com>
>> To: <fw-general@lists.zend.com>
>> Sent: Wednesday, July 01, 2009 4:04 PM
>> Subject: [fw-general] Error rounding float value with
>> Zend_Locale_Format::toNumber()
>>
>>
>>>
>>> Hi.
>>>
>>> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber()
>>> and
>>> I
>>> get result 98, I expected 99.00.
>>>
>>> I've just added new issue
>>> http://framework.zend.com/issues/browse/ZF-7170.
>>> Do you think I'm wrong somewhere in my code?
>>>
>>> Regards,
>>> Sasa Stamenkovic.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24292705.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
thomasW

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Then set the wished locale.
When you don't set the locale then it will not be used.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "umpirsky" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, July 02, 2009 8:49 AM
Subject: Re: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()



Yes, with toFloat() I get string(5) "99.00", but I wanted to have string(5)
"99,00" when using sv_SE locale.

Regards,
Saša Stamenković


thomasW wrote:

>
> It's the same reason as for toFloat().
>
> But the used number format is different for each of the functions.
> toInteger(), toFloat() and toNumber() all define different formats and
> therefor they all handle number differently. When this would not be the
> case, then there would have been no reason to create 3 methods. :-)
>
> You could get the same result within toNumber() when you define that the
> number format has to be rounded instead of truncated.
>
> Greetings
> Thomas Weidner, I18N Team Leader, Zend Framework
> http://www.thomasweidner.com
>
>
> ----- Original Message -----
> From: "umpirsky" <[hidden email]>
> To: <[hidden email]>
> Sent: Wednesday, July 01, 2009 6:18 PM
> Subject: Re: [fw-general] Error rounding float value with
> Zend_Locale_Format::toNumber()
>
>
>>
>> Hm, maybe, but what is precision for in toNumber method then? And why it
>> works for most cases and not for this particular one?
>>
>> Regards,
>> Sasa Stamenkovic.
>>
>>
>> thomasW wrote:
>>>
>>> Shouldn't you use toFloat when you want to have a float value ?
>>>
>>> Greetings
>>> Thomas Weidner, I18N Team Leader, Zend Framework
>>> http://www.thomasweidner.com
>>>
>>> ----- Original Message -----
>>> From: "umpirsky" <[hidden email]>
>>> To: <[hidden email]>
>>> Sent: Wednesday, July 01, 2009 4:04 PM
>>> Subject: [fw-general] Error rounding float value with
>>> Zend_Locale_Format::toNumber()
>>>
>>>
>>>>
>>>> Hi.
>>>>
>>>> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber()
>>>> and
>>>> I
>>>> get result 98, I expected 99.00.
>>>>
>>>> I've just added new issue
>>>> http://framework.zend.com/issues/browse/ZF-7170.
>>>> Do you think I'm wrong somewhere in my code?
>>>>
>>>> Regards,
>>>> Sasa Stamenkovic.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
>>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24292705.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
>

--
View this message in context:
http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24302050.html
Sent from the Zend Framework mailing list archive at Nabble.com.

umpirsky

Re: Error rounding float value with Zend_Locale_Format::toNumber()

Reply Threaded More More options
Print post
Permalink
Hm, now it works, with toFloat and locale set.

Thanks.

thomasW wrote:
Then set the wished locale.
When you don't set the locale then it will not be used.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "umpirsky" <umpirsky@gmail.com>
To: <fw-general@lists.zend.com>
Sent: Thursday, July 02, 2009 8:49 AM
Subject: Re: [fw-general] Error rounding float value with
Zend_Locale_Format::toNumber()



Yes, with toFloat() I get string(5) "99.00", but I wanted to have string(5)
"99,00" when using sv_SE locale.

Regards,
Saša Stamenković


thomasW wrote:
>
> It's the same reason as for toFloat().
>
> But the used number format is different for each of the functions.
> toInteger(), toFloat() and toNumber() all define different formats and
> therefor they all handle number differently. When this would not be the
> case, then there would have been no reason to create 3 methods. :-)
>
> You could get the same result within toNumber() when you define that the
> number format has to be rounded instead of truncated.
>
> Greetings
> Thomas Weidner, I18N Team Leader, Zend Framework
> http://www.thomasweidner.com
>
>
> ----- Original Message -----
> From: "umpirsky" <umpirsky@gmail.com>
> To: <fw-general@lists.zend.com>
> Sent: Wednesday, July 01, 2009 6:18 PM
> Subject: Re: [fw-general] Error rounding float value with
> Zend_Locale_Format::toNumber()
>
>
>>
>> Hm, maybe, but what is precision for in toNumber method then? And why it
>> works for most cases and not for this particular one?
>>
>> Regards,
>> Sasa Stamenkovic.
>>
>>
>> thomasW wrote:
>>>
>>> Shouldn't you use toFloat when you want to have a float value ?
>>>
>>> Greetings
>>> Thomas Weidner, I18N Team Leader, Zend Framework
>>> http://www.thomasweidner.com
>>>
>>> ----- Original Message -----
>>> From: "umpirsky" <umpirsky@gmail.com>
>>> To: <fw-general@lists.zend.com>
>>> Sent: Wednesday, July 01, 2009 4:04 PM
>>> Subject: [fw-general] Error rounding float value with
>>> Zend_Locale_Format::toNumber()
>>>
>>>
>>>>
>>>> Hi.
>>>>
>>>> I tried to round 98.99999625 value with Zend_Locale_Format::toNumber()
>>>> and
>>>> I
>>>> get result 98, I expected 99.00.
>>>>
>>>> I've just added new issue
>>>> http://framework.zend.com/issues/browse/ZF-7170.
>>>> Do you think I'm wrong somewhere in my code?
>>>>
>>>> Regards,
>>>> Sasa Stamenkovic.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24290360.html
>>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24292705.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
>

--
View this message in context:
http://www.nabble.com/Error-rounding-float-value-with-Zend_Locale_Format%3A%3AtoNumber%28%29-tp24290360p24302050.html
Sent from the Zend Framework mailing list archive at Nabble.com.