Vivek Modi
03/14/2022, 4:34 PMval string = "2.2"
I want to show in textview like 2.2
. But if my string is 2.00
it will show 2
in my textview. How can I do this in kotlin efficient way?Tim Oltjenbruns
03/14/2022, 4:45 PMTim Oltjenbruns
03/14/2022, 4:46 PMVivek Modi
03/14/2022, 8:24 PMAbinet Zelalem
03/14/2022, 8:48 PMNumberFormat
for this. You can do something like this if you have a locale. Remember to check for empty and non numeric values in your string when converting to double.
NumberFormat.getInstance(Locale("en", "US"))
.format(yourStringInDouble).replace(".00", "")
Tim Oltjenbruns
03/14/2022, 9:09 PMVivek Modi
03/14/2022, 9:14 PMnot harcode it to english
?Abinet Zelalem
03/14/2022, 9:15 PMLocale("en", "US")
, use the Locale of the deviceTim Oltjenbruns
03/14/2022, 9:16 PMLocale("en", "US")
Tim Oltjenbruns
03/14/2022, 9:16 PMTim Oltjenbruns
03/14/2022, 9:17 PMVivek Modi
03/14/2022, 9:18 PMDaniel B Duval
03/16/2022, 11:20 PM,
for decimals would show 2,00
.