Normalize Scientific Notation
Python
Medium
4 views
Problem Description
A number is provided as a string, it may be in scientific notation like 1e3 or 2.50E-1. Output it as normal decimal without exponent and remove extra trailing zeros.
Input Format
One number as string.
Output Format
One normalized decimal string.
Official Solution
import sys
from decimal import Decimal
s=sys.stdin.read().strip()
if not s: sys.exit(0)
x=Decimal(s)
t=format(x,'f')
if '.' in t:
t=t.rstrip('0').rstrip('.')
if t=='-0':
t='0'
sys.stdout.write(t)
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!