# How do you round a number to N decimal places

**URL:** <https://discuss.kotlinlang.org/t/how-do-you-round-a-number-to-n-decimal-places/8843>\
**Category:** Support\
**Created:** [August 2, 2018, 1:08pm UTC](https://discuss.kotlinlang.org/t/how-do-you-round-a-number-to-n-decimal-places/8843 "2018-08-02T13:08:19Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![tagaev](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@tagaev](https://discuss.kotlinlang.org/u/tagaev)\
**Post date:** [December 17, 2020, 7:01am UTC](https://discuss.kotlinlang.org/t/how-do-you-round-a-number-to-n-decimal-places/8843/16 "2020-12-17T07:01:07Z")

</div>

Take a look for this method, in my case it works:

```auto
fun Double.roundTo(numFractionDigits: Int): Double {
  val factor = 10.0.pow(numFractionDigits.toDouble())
  return (this * factor).roundToInt() / factor
}

```

i borrow this from: [java - Round Double to 1 decimal place kotlin: from 0.044999 to 0.1 - Stack Overflow](https://stackoverflow.com/a/51689453/12102080)

---

_[View the full topic](https://discuss.kotlinlang.org/t/how-do-you-round-a-number-to-n-decimal-places/8843)._
