kotlin中的php number_format

问题描述 投票:0回答:1

我知道php中的number_format函数。我在科特林需要类似的东西。我找到了Java类NumberFormat,但它没有满足我的需要。 DecimalFormat也不会这样做。我还发现了有关数字格式的this answered question,但是当我使用“ 0 + 000,00”或“#+ ###,##”作为格式模式时,它会崩溃。

我需要将数字的格式设置为275 + 756,24。

在php中,我可以使用number_format(275756.24,2,",","+")

kotlin中是否有类似功能?

来自巴拉圭的问候。

Claudio Bogado Pompa。

php kotlin
1个回答
0
投票

我希望这是一个更短的方法。

val value = 275756.24
val formatter = DecimalFormat("#,###.##")
val symbols = formatter.decimalFormatSymbols
symbols.groupingSeparator = '+'
symbols.decimalSeparator = ','
formatter.decimalFormatSymbols = symbols
val result = formatter.format(value)

感谢Jeto。

© www.soinside.com 2019 - 2024. All rights reserved.