Page 1 of 1
Dollars and Cents
Posted: Thu Jan 14, 2010 1:12 pm
by mariolopes
Hi
I need to save on price in my table. I get the dollars and cents separately. How can i save the full amount?
Thank you
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 1:35 pm
by pickle
Concatenate
Code: Select all
$dollars = 12;
$cents = 95;
$full = $dollars.'.'.$cents;
Or add
Code: Select all
$dollars = 12;
$cents = 95;
$full = $dollars + ($cents/100);
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 4:43 pm
by mariolopes
Thank you
but i get one string: $full = $dollars.'.'.$cents;
How can i convert this string to money, because i want to save his value in mysql table?
Thank you
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 5:23 pm
by Eran
If we could convert strings to money, we'd all be filthy rich by now...
Seriously though, you need to explain what you meant by that. 'money' is not a data type
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 5:25 pm
by mariolopes
You're right
I need to convert string -> decimal. I think i found the answer at
http://php.net/manual/en/function.intval.php
Thank you
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 5:35 pm
by Eran
I don't think intval() is what you're looking for then, perhaps number_format() is what you need -
http://php.net/manual/en/function.number-format.php
Re: Dollars and Cents
Posted: Thu Jan 14, 2010 5:57 pm
by AbraCadaver
mariolopes wrote:Thank you
but i get one string: $full = $dollars.'.'.$cents;
How can i convert this string to money, because i want to save his value in mysql table?
Thank you
Just insert it into MySQL without quotes around it in your query.