# Math.roundWithPrecision issue

**URL:** https://forum.makecode.com/t/math-roundwithprecision-issue/200
**Category:** PXT
**Created:** [May 24, 2019, 5:23pm UTC](https://forum.makecode.com/t/math-roundwithprecision-issue/200 "2019-05-24T17:23:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![darzu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/darzu/32/1882_2.png) [@darzu](https://forum.makecode.com/u/darzu)
#### Post date: [May 24, 2019, 5:23pm UTC](https://forum.makecode.com/t/math-roundwithprecision-issue/200/1 "2019-05-24T17:23:29Z")

</div>

From a message on Twitter:

* * *

I have the code: let lectura = 0  
input.onButtonPressed(Button.A, function () {  
lectura = pins.analogReadPin(AnalogPin.P0)  
basic.showNumber(escalado(lectura))  
})  
function escalado(valor: number) {  
let resultado = 0  
resultado = (valor \* 3) / 1023  
return Math.roundWithPrecision(resultado, 2)

}

the idea is measure volt from input

I want only see for example 1.47 when I measure a small battery

that is rigth into emulator screen but when I load the program I see 1.4699999999…

why do I see this result into the led screen? could you help me to understand it?

* * *

I think this might be a bug with “roundWithPrecision”  
@michal, do we know if Math.roundWithPrecision is expected to work on HW?

---

<div class="post-metadata">

### Author: ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)
#### Post date: [May 24, 2019, 6:27pm UTC](https://forum.makecode.com/t/math-roundwithprecision-issue/200/2 "2019-05-24T18:27:28Z")

</div>

I believe it rounds - the number seems rounded to two decimal points. It just that we print it out wrong, the code is rather simplistic [https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/core.cpp#L1088](https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/core.cpp#L1088)

Printing out floating point numbers is rather a complex task.
