Parse Money String

Parse Money String

Medium PHP PHP Data Types 24 views
Explanation Complexity

Problem Statement

Input like 1,234.50. Remove commas and print the number with 2 decimals.

Input Format

One token amount.

Output Format

One number with 2 decimals.

Example

1,234.50
1234.50

Constraints

|amount|

Input / Output Format

Input Format
One token amount.
Output Format
One number with 2 decimals.
Constraints
|amount|

Examples

Input:
1,234.50
Output:
1234.50

Example Solution (Public)

PHP
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputText=str_replace(',','',$inputText);
$val=floatval($inputText);
echo number_format($val,2,'.','');
?>

Official Solution Code

<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputText=str_replace(',','',$inputText);
$val=floatval($inputText);
echo number_format($val,2,'.','');
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.