Round to K Decimals
PHP
Hard
4 views
Problem Description
Input x and k. Print x rounded to k decimals.
Input Format
One line: x k.
Output Format
One number with k decimals.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$x,$k]=preg_split('/\\s+/', $inputText, 2);
$k=intval($k);
$val=floatval($x);
echo number_format(round($val,$k),$k,'.','');
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!