lightmaster2006 - 1 year ago 104

iOS Question

I have a calculation that calculate square meters from millimeters and for this to show corect I would like to remove all numbers after the 2 first digits.

This is what I have tried so far.

`let spha = sizeh.wshight()`

let spwa = sizew.wswidth()

let areas1 = areaModel(pwa:spwa, pha:spha)

let formatter5 = NSNumberFormatter ()

formatter5.maximum = 2

let scarea = formatter5.stringFromNumber(areas1.sarea())!

screenAreaLabel?.text = "\(scarea)sqm"

I am a little lost at this point, I am using Float in calculation of this area.

Hope someone could help me in the right direction.

More detail info added.

I would like the Screen Area to only show 24sqm not 24772610sqm

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You are multiplicating a value in millimeter by anothe value in milliters, therefore the result is in square millimeters.

To convert square millimeters to square meters, just divide the result by `1_000_000`

.

You could also set `formatter.multiplier`

to `1.0 / 1_000_000`

.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**