You can get the Integer part as follows:
let d: Double = 1.23456e12 let intparttruncated = trunc(d) let intpartroundlower = Int(d)
The trunc () function truncates the part after the decimal point, and the Int () function rounds to the next lower value. This is the same for positive numbers, but the difference is for negative numbers. If you subtract the truncated part from d, then you get the fractional part.
func frac (_ v: Double) -> Double { return (v - trunc(v)) }
You can get Mantissa and Exponent of double value as follows:
let d: Double = 1.23456e78 let exponent = trunc(log(d) / log(10.0)) let mantissa = d / pow(10, trunc(log(d) / log(10.0)))
Your result will be 78 for the exhibitor and 1.23456 for the Mantissa.
Hope this helps you.
jscom source share