Zend Framework

Can't set value with comma for currency

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.10.5
  • Fix Version/s: 1.10.7
  • Component/s: Zend_Currency
  • Labels:
    None

Description

In Poland there is use comma "," insted of dot "." in numbers.
Zend_Currency correctly shows values but I can not set number as string with comma.

I use locale 'pl_PL' and PLN.

$curr->setValue('123,45'); //as string

ps

Activity

Hide
Thomas Weidner added a comment -

Closing as non-issue.

According to the manual and the API setValue() accepts:

  • integer
  • float
  • Zend_Currency

A localized string is no valid input. When you want to give a localized string as value then you need to normalize it before or extend Zend_Currency to do this.

Reason: "value" is internally a float.

Show
Thomas Weidner added a comment - Closing as non-issue. According to the manual and the API setValue() accepts:
  • integer
  • float
  • Zend_Currency
A localized string is no valid input. When you want to give a localized string as value then you need to normalize it before or extend Zend_Currency to do this. Reason: "value" is internally a float.
Hide
Przemyslaw Sobczuk added a comment -

I think that it shoud be dependet from locale settings at all.

Keep on mind that showing currency is with locale settings:
in pl_PL locale
$curr->setValue('123.45'); //value must be set with dot, I can't set value with comma
echo $curr; // 123,45 - always print comma = correct for Poland

It's illogical.

Value should be set directly (without changes) from forms.

Notice. Numeric keyborad (right side of keyboard) in polish standard has got comma insted of dot. It's default for us. Writing float numbers with dot is problematic.

"Value" should be internally a float, as is.

Show
Przemyslaw Sobczuk added a comment - I think that it shoud be dependet from locale settings at all. Keep on mind that showing currency is with locale settings: in pl_PL locale $curr->setValue('123.45'); //value must be set with dot, I can't set value with comma echo $curr; // 123,45 - always print comma = correct for Poland It's illogical. Value should be set directly (without changes) from forms. Notice. Numeric keyborad (right side of keyboard) in polish standard has got comma insted of dot. It's default for us. Writing float numbers with dot is problematic. "Value" should be internally a float, as is.
Hide
Thomas Weidner added a comment -

Again:
A string is not accepted as input. You need to make a float.

You can set it from within a form... add a filter.

Also your notice is not logical... when you use a polish keyboard we can also expect that your environment locale is polish which means that PHP itself does the conversion for you. When not: Add a filter.

Show
Thomas Weidner added a comment - Again: A string is not accepted as input. You need to make a float. You can set it from within a form... add a filter. Also your notice is not logical... when you use a polish keyboard we can also expect that your environment locale is polish which means that PHP itself does the conversion for you. When not: Add a filter.
Hide
Przemyslaw Sobczuk added a comment -

You are right that I can use filter. It can solve my problem but it is one more thing to remember while creating form. As well I can use str_replace(',','.',$str);

All incoming data from forms are strings.
Float numbers contains comma insted of dot.
Simple conversion done by the Zend_Currency ($val = floatval( $val ) gives me only an integer part of that string.

As you said I can use filters, but it would be more convenient if the class did it automatically based on Zend_Locale.

If you think I am wrong you can close this ticket.

Thanks for taking the time.

ps

Show
Przemyslaw Sobczuk added a comment - You are right that I can use filter. It can solve my problem but it is one more thing to remember while creating form. As well I can use str_replace(',','.',$str); All incoming data from forms are strings. Float numbers contains comma insted of dot. Simple conversion done by the Zend_Currency ($val = floatval( $val ) gives me only an integer part of that string. As you said I can use filters, but it would be more convenient if the class did it automatically based on Zend_Locale. If you think I am wrong you can close this ticket. Thanks for taking the time. ps
Hide
Ian Monge added a comment -

You can use this:

$filter = new Zend_Filter_LocalizedToNormalized();
$filter->filter('53,95);

It returns a string:

53.95

Show
Ian Monge added a comment - You can use this:
$filter = new Zend_Filter_LocalizedToNormalized(); $filter->filter('53,95);
It returns a string: 53.95

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: