I have form where to write one number and other form to write one more number. And I need for example multiply both numbers.
If someone enters number with comma (for example 200,51) php script thinks that number is 200 (without ,55)
how to convert comma to number?
How to convert point as decimal separator to comma?
Moderator: General Moderators
Re: How to convert point as decimal separator to comma?
U need two steps to do this ... the first by explode the number entered by the user into an array (if there is multiple commas then the make sure that the number type is string otherwise u will get error msg! )
then implode this number again without any spaces or commas and u will just a number without commas
and I tested the code for u and it gave me this output:
now the number is 123123123
Regards,
Noor
then implode this number again without any spaces or commas and u will just a number without commas
Code: Select all
$number= "123,123,123";
$number= explode(',',$number);
$number= implode ($number);
echo "now the number is $number<br>";
now the number is 123123123
Regards,
Noor
Re: How to convert point as decimal separator to comma?
Thanks.
I have found one more solution
<?php $output = floatval(ereg_replace("[^-0-9\.]","",$input)); ?>
But the next problem
If i enter for example 22.5
i get displayed 22.5
but i need 22.50 with zero.
round ($output, 2) does not help....
Found solution
<?php printf("%.2f", $output); ?>
I have found one more solution
<?php $output = floatval(ereg_replace("[^-0-9\.]","",$input)); ?>
But the next problem
If i enter for example 22.5
i get displayed 22.5
but i need 22.50 with zero.
round ($output, 2) does not help....
Found solution
<?php printf("%.2f", $output); ?>