Parse Money String
PHP
Medium
4 views
Problem Description
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.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputText=str_replace(',','',$inputText);
$val=floatval($inputText);
echo number_format($val,2,'.','');
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!