Answers for "reverse money_format to float php"

PHP
0

reverse money_format to float php

You can use filter_var. e.g.

$num = '1,200,998';
$real_integer = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
echo $real_integer;

will output:
1200998
  
######## OR #########
$number1= '$ 1,989.34';

$number2 = filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
// output: 1989.34
$number2 = filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
// output: 1,98934

reference:
https://stackoverflow.com/questions/2935906/how-do-i-convert-output-of-number-format-back-to-numbers-in-php
Posted by: Guest on June-22-2021

Browse Popular Code Answers by Language