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
Dollars and Cents
Moderator: General Moderators
Re: Dollars and Cents
Concatenate
Or add
Code: Select all
$dollars = 12;
$cents = 95;
$full = $dollars.'.'.$cents;Code: Select all
$dollars = 12;
$cents = 95;
$full = $dollars + ($cents/100);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: Dollars and Cents
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
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
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
Seriously though, you need to explain what you meant by that. 'money' is not a data type
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: Dollars and Cents
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
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
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
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Dollars and Cents
Just insert it into MySQL without quotes around it in your query.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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.