#C2697. Compute Decimal Equivalent of a Fraction
Compute Decimal Equivalent of a Fraction
Compute Decimal Equivalent of a Fraction
You are given a fraction in the form , where and are integers and . Your task is to compute the decimal equivalent of the fraction rounded to four decimal places. If the denominator is zero or the input string does not represent a valid fraction, output None
. Note that the fraction may be negative, and the negative sign can appear in the numerator, the denominator, or both.
For example, for an input of 3/4
, the output should be 0.7500
; for 10/3
, it should be 3.3333
; and for 2/0
or an invalid string like not a fraction
, the output should be None
.
You must read the input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The input consists of a single line containing a fraction in the format N/D
. Here, N
and D
are integers. There are no extra spaces in the input.
outputFormat
Output a single line containing either the decimal equivalent of the fraction rounded to four decimal places or None
if the fraction is invalid or if the denominator is zero.## sample
3/4
0.7500
</p>