https://kotlinlang.org logo
j

jlleitschuh

08/17/2017, 3:04 PM
Very simple proposal. Add an extension function to
Double
so you can do this:
0.5.toBigDecimal()
r

Ruckus

08/17/2017, 3:27 PM
Isn't it considered bad practice to create a BigDecimal from a Double or Float?
o

orangy

08/17/2017, 3:29 PM
You can create an extension property:
Copy code
val <http://Double.bd|Double.bd> : BigDecimal get() = BigDecimal(this)

val value = 0.5.bd
👎 1
👍 1
d

dmitry.petrov

08/17/2017, 8:26 PM
I'd prefer it as
fun Double.toBigDecimal()
, because that's a conversion function, just like
toMutableList
.
r

Ruckus

08/17/2017, 8:28 PM
@dmitry.petrov Isn't that what's coming in 1.2?
d

dmitry.petrov

08/17/2017, 8:31 PM
Yes it is. Just explained what I don't like about
.bd
r

Ruckus

08/17/2017, 8:34 PM
Ah, sorry. I though you were responding to @elizarov, so I got a bit confused.
2 Views