Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Formatting decimal and money values?? Possible duplicate


Reply


2 Posts   633 Views

Avatar
Nadz

Community Member, 8 Posts

10 April 2012 at 5:24pm

I am kinda new to SS.

In my model I have Price as Decimal. In the template views, i can display the Price which is OK.

But I intend to format the Prices as below
20.00 should return 20
25.99 should return 25.99

What is the best approach of getting this done in SS??

Thanks in advance.

Nadz

Avatar
zenmonkey

Community Member, 532 Posts

11 April 2012 at 6:10am

Well php has a money_format() function which is kind of fun. But at the most basic level you can just do a str_replace() on the price like

function NicePrice() {
$offset = strpos($this->Price, '.00'); //checks to see if .00 exists in Prices
if ($offset === false) {
return str_replace('.00', '', $this->Price); //if .00 exists it replaces it with nothing
} else {
return $this->Price; //if it doesn't exist it just returns the original value
}
}


Then all you need to do is call $NicePrice in your template