reverse money format to float php

Solutions on MaxInterview for reverse money format to float php by the best coders in the world

showing results for - "reverse money format to float php"
Noa
16 Jul 2020
1You can use filter_var. e.g.
2
3$num = '1,200,998';
4$real_integer = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
5echo $real_integer;
6
7will output:
81200998
9  
10######## OR #########
11$number1= '$ 1,989.34';
12
13$number2 = filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
14// output: 1989.34
15$number2 = filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
16// output: 1,98934
17
18reference:
19https://stackoverflow.com/questions/2935906/how-do-i-convert-output-of-number-format-back-to-numbers-in-php