# Print floats with certain amount of decimal numbers

**URL:** <https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812>\
**Category:** Support\
**Created:** [June 20, 2016, 11:11am UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812 "2016-06-20T11:11:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![achobanov](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@achobanov](https://discuss.kotlinlang.org/u/achobanov)\
**Post date:** [June 20, 2016, 11:11am UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/1 "2016-06-20T11:11:02Z")

</div>

Hello,

I am trying to print a float with two decimal symbols. How to do that?

---

<div class="post-metadata">

**Author:** ![molchanoviv](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/molchanoviv/32/1846_2.png) [@molchanoviv](https://discuss.kotlinlang.org/u/molchanoviv)\
**Post date:** [June 20, 2016, 11:57am UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/2 "2016-06-20T11:57:25Z")

</div>

Use DecimalFormat

---

<div class="post-metadata">

**Author:** ![udalov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/udalov/32/5679_2.png) [@udalov](https://discuss.kotlinlang.org/u/udalov)\
**Post date:** [June 20, 2016, 12:42pm UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/3 "2016-06-20T12:42:05Z")

</div>

`"%.2f".format(value)`

---

<div class="post-metadata">

**Author:** ![JorgeCastillo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jorgecastillo/32/2873_2.png) [@JorgeCastillo](https://discuss.kotlinlang.org/u/JorgeCastillo)\
**Post date:** [June 21, 2017, 2:40pm UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/4 "2017-06-21T14:40:47Z")

</div>

is that returning “19.00” for values with 0 as the decimal part?

---

<div class="post-metadata">

**Author:** ![dicklucas](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dicklucas/32/4489_2.png) [@dicklucas](https://discuss.kotlinlang.org/u/dicklucas)\
**Post date:** [December 4, 2017, 4:23pm UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/5 "2017-12-04T16:23:10Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![carstenhag](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/carstenhag/32/10650_2.png) [@carstenhag](https://discuss.kotlinlang.org/u/carstenhag)\
**Post date:** [December 7, 2023, 4:01pm UTC](https://discuss.kotlinlang.org/t/print-floats-with-certain-amount-of-decimal-numbers/1812/6 "2023-12-07T16:01:35Z")

</div>

I know that I am replying on a really old thread, but I found this googling for “format float with point kotlin”.

Note that `kotlin.String.format` is locale-dependant! Depending on the runtime locale, it will output `11,34` or `11.34`. To be honest, I don’t know why the method without locale is not deprecated, because other methods have been deprecated before due to this inconsistent behavior 😃

To avoid this, use something like `"%2.f".format(Locale.ROOT, value)`.

I was trying to format Latitude/Longitude and having inconsistent “,”/“.” introduced a bug for us.
