Round to K Decimals

Round to K Decimals

Hard PHP PHP Data Types 21 views
Explanation Complexity

Problem Statement

Input x and k. Print x rounded to k decimals.

Input Format

One line: x k.

Output Format

One number with k decimals.

Example

3.14159 3
3.142

Constraints

0

Input / Output Format

Input Format
One line: x k.
Output Format
One number with k decimals.
Constraints
0

Examples

Input:
3.14159 3
Output:
3.142

Example Solution (Public)

PHP
<?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,'.','');
?>

Official Solution Code

<?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,'.','');
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.