3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 296 Views |
-
Formatting decimal and money values?? Possible duplicate

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.99What is the best approach of getting this done in SS??
Thanks in advance.
Nadz
-
Re: Formatting decimal and money values?? Possible duplicate

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
| 296 Views | ||
|
Page:
1
|
Go to Top |


