Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data type for currency in Kotlin

Tags:

android

kotlin

I'm new for Kotlin. I did search and read the docs but couldn't figure out What the best data type to use in Kotlin for currency. In Java there is BigDecimal. Is there something similar in Kotlin? Thanks in advance.

like image 313
user1818125 Avatar asked Aug 22 '18 11:08

user1818125


1 Answers

You can use BigDecimal in kotlin too.

var num1 : BigDecimal? = BigDecimal.ZERO

var num2  = BigDecimal("67.9") 

Also you can use Double data type and then you can use toBigDecimal() for convert it to BigDecimal.

For the more details :- https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/to-big-decimal.html

like image 111
Yohan Malshika Avatar answered Sep 18 '22 17:09

Yohan Malshika