Half Up Rounding
Python
Easy
3 views
Problem Description
A decimal number x is provided. Round it to nearest integer (0.5 goes away from zero) and output the integer.
Input Format
One decimal number as string.
Output Format
One integer rounded.
Constraints
Input has at most 30 characters.
Official Solution
import sys
from decimal import Decimal,ROUND_HALF_UP
s=sys.stdin.read().strip()
if not s: sys.exit(0)
x=Decimal(s)
y=x.quantize(Decimal('1'), rounding=ROUND_HALF_UP)
sys.stdout.write(str(int(y)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!