Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal number with comma instead of point (php and sql)

Tags:

sql

php

I'm doing a little application of adding prices and decimals. Points are normal to use with decimals, but how can I write decimal number with comma as input (543,35 instead of 543.35) and then maybe change it with point to the database (mysql)? Then print it back form the database with the comma. Reason is that comma (,) is more used in Finland than point (.) when write decimal numbers.

Thank you very much!

Samuel

like image 454
sk. Avatar asked Jan 04 '10 21:01

sk.


1 Answers

$input  = '5,50';
$output = str_replace(',', '.', $input);
var_dump($output); // string(4) "5.50"
$number = (float)$output;
var_dump($number); // float(5.5)
like image 161
Stefan Gehrig Avatar answered Sep 30 '22 15:09

Stefan Gehrig