• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [SOLVED] retreive number from text input field
PostPosted: Fri Jul 26, 2013 3:47 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sat Jul 12, 2008 3:50 am
Posts: 425
Location: Zeist, Netherlands
Using ListIt2 (version 1.4) I was in need of a decimal number field to add prices to my items, but no such fields are provided for. So I decided to use a text input field instead.
In order to get a correct output (decimal point and two digits) I created a UDT number_from_text that uses PHP function number_format().
The tag is {number_from_text price="1234.56"}.
\$1:
$price = number_format($params['price'], 2, ',', '.');
echo $price;

The output is 1.234,56*, which can be used for display at the website's front.
Of course this tag can also be used for weight or any other decimal number.
Need 3 digits in stead of 2? A decimal point instead of comma? A space instead of a point to seperate thousands? Just change the parameters of number_format().

Frank

* The output is always with 2 digits, independent of the input in the text input field. So if you have a price of say €10, it does not matter whether you enter 10 or 10,0 or 10,00 - the output will always be 10,00.
It also doesn't matter whether in the input field you use a comma, a point or the decimal point of the number keys - they will all be recognized as decimal point.


Last edited by frankmanl on Sun Nov 10, 2013 3:41 am, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: retreive number from text input field
PostPosted: Fri Jul 26, 2013 9:10 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 2071
Location: Feldkirchen in Kärnten, Austria
There is no need for a UDT, you can use number_format Smarty modifier to achieve same goal.

\$1:
{$foo|number_format:2:',':'.'}


or assigning

\$1:
{$mynumber = number_format($foo, 2, ',', '.')}
{$mynumber}

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: jakubr


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting