Answers for "php format float as currency"

PHP
2

format php currency

<?php
// beware: number_format also rounds

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
Posted by: Guest on May-19-2020
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

Code answers related to "php format float as currency"

Browse Popular Code Answers by Language