Home > Zend framework > zend framework convert Việt nam đồng

zend framework convert Việt nam đồng

zend framework version < 2 hiển thị giá sản phẩm theo Việt nam đồng , USD

Tao viết thành hàm như sau:


function product_price($type, $value){

	if(strtoupper($type) == "VND"){

		$price = $value+0;
		$currency = new Zend_Currency(
				array(
				   "value"			=>$price,                           
				   "currency"		=>"VND",
				   "symbol"			=>"đ",
				   "display"		=>2,
				   "precision"		=>0,
				   "number_format" 	=>"#.##0.00",
				   "locale"			=>"vi_VN",
				   "position"		=>Zend_Currency::RIGHT)
				);
		return $currency->toCurrency();

	}elseif(strtoupper($type) == 'USD'){
		$currency = new Zend_Currency('en_US');
		$helper = new Zend_View_Helper_Currency($currency);			
		return $helper->currency($value);
	}		

}

ví dụ:

product_price('VND', 250000) //output 250.000 đ 

Chúc các bạn thành công

PHP Developer
nhantam

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: