Normalize Scientific Notation

Normalize Scientific Notation

Medium Python Data Types 17 views
Explanation Complexity

Problem Statement

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

• First line: A string representing a number

• It may be in scientific notation (e.g., 1e3, 2.50E-1)

• Or a normal decimal number

Output Format

• Print the number in normal decimal form

• Do not use exponent format

• Remove unnecessary trailing zeros

• Do not keep trailing decimal point

Example

2.50E-1
0.25

Constraints

• The input is a valid numeric string

• Length ≤ 10^5

Concept Explanation

Input: 2.50E-1

Scientific meaning:
2.50 × 10⁻¹ = 0.25

Remove trailing zeros → 0.25

If input was:

• 1e3 → Output 1000

• 3.0000 → Output 3

• 5.2300 → Output 5.23

Step-by-Step Explanation

1.Read the number as a string.

2.Convert it to a Decimal (from decimal module) to correctly handle scientific notation.

3.Convert the Decimal value to normal string format (no exponent).

4.If there is a decimal point:

• Remove trailing zeros after decimal.

• If decimal point remains at the end, remove it.

5.Print the final formatted string.

Concept Explanation

Input: 2.50E-1

Scientific meaning:
2.50 × 10⁻¹ = 0.25

Remove trailing zeros → 0.25

If input was:

• 1e3 → Output 1000

• 3.0000 → Output 3

• 5.2300 → Output 5.23

Step-by-Step Explanation

1.Read the number as a string.

2.Convert it to a Decimal (from decimal module) to correctly handle scientific notation.

3.Convert the Decimal value to normal string format (no exponent).

4.If there is a decimal point:

• Remove trailing zeros after decimal.

• If decimal point remains at the end, remove it.

5.Print the final formatted string.

Input / Output Format

Input Format
• First line: A string representing a number

• It may be in scientific notation (e.g., 1e3, 2.50E-1)

• Or a normal decimal number
Output Format
• Print the number in normal decimal form

• Do not use exponent format

• Remove unnecessary trailing zeros

• Do not keep trailing decimal point
Constraints
• The input is a valid numeric string

• Length ≤ 10^5

Examples

Input:
2.50E-1
Output:
0.25

Example Solution (Public)

Python
import sysnfrom decimal import Decimalns=sys.stdin.read().strip()nif not s: sys.exit(0)nx=Decimal(s)nt=format(x,'f')nif '.' in t:n  t=t.rstrip('0').rstrip('.')nif t=='-0':n  t='0'nsys.stdout.write(t)

Official Solution Code

import sysnfrom decimal import Decimalns=sys.stdin.read().strip()nif not s: sys.exit(0)nx=Decimal(s)nt=format(x,'f')nif '.' in t:n  t=t.rstrip('0').rstrip('.')nif t=='-0':n  t='0'nsys.stdout.write(t)
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.