Reputation: 538
I have a table called "Prices" with one field name "value" and set to decimal. I want to be able to insert a string such as "3.5$" and that mysql will insert the number "3.5". No success so far.
Upvotes: 1
Views: 293
Reputation: 38584
Use floatval
$NumberWithString = 3.5$;
floatval($NumberWithString);
Example
<?php
$var = '122.34343The';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
?>
EDIT 01
Or use preg_replace
$newNumber = preg_replace('/$/', '', $NumberWithString);
Upvotes: 1
Reputation: 1819
update yourtable
set yourdecimal = cast('3.7$' as decimal(10,2))
where id = 1
Upvotes: 1