Given a number between 0 and 1 and another integer, print the approximated value of the first number rounded off to the specified number of digits given by the second integer. For example, if the input is
0.3212312312 , 2 then the output is:
The number of digits after the dot should always equal the second input integer.
The input will always be
([)number from 0-1 , integer above 0(])
Predefined round functions are allowed.
The first input number will not have any trailing 0's
Always use a dot for input and output. Commas are not allowed.
Fractions are allowed as output with the notation
number/numberbut try to just use a decimal notation.
[Trailing zero rule removed due to that i should have been faster]
- Rounding should always be done to the closest number so up if above 4 and down if under 5.
Input: 0.31231231231 , 1
Input: 0.1, 10
Input: 0.01231231231 , 9
This is code-golf. Shortest answer in bytes wins.
Suggestion for making this challenge better are appreciated. Have fun golfing!
definition of this challenge by Francisco Hahn:
shortest way to round a float X with precision N on each language