Create BigDecimal via 10.dec or 10.9.dec or "10".dec #282
CodeServant
started this conversation in
Ideas
Replies: 2 comments
-
I think it's an interesting idea, /**
* Converts a number to big decimal, optionally modifies the exponent and provides decimal mode.
* Example:
* 1234.0.toBigDecimal() produces 1.234E3
* 1234.0.toBigDecimal(exponentModifier = 2) produces 1.234E5 (original exponent was 3 and modifier adds 2)
*/
fun Double.toBigDecimal(exponentModifier: Long? = null, decimalMode: DecimalMode? = null): BigDecimal {
return BigDecimal.fromDouble(this, decimalMode).moveDecimalPoint(exponentModifier ?: 0)
} the approach with extension property would miss this abilty to set decimalMode and modify exponent. I guess this could become a discussion? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I didn't take that into account. So if, to implement it, this shoud be still extension function, but with shorter name. Maby this is not a good idea. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
Since
BigDecimal
is just a number, I think this is a bit inconvenient to call every time10.toBigDecimal()
when I want to treat number as BigDecimal.Describe the solution you'd like
Change (hide) BigDecimal creation behind something like
n.dec
where n is some number. This is very simple to implement with extension valueDescribe alternatives you've considered
Alternative is the status quo or different naming. There is extension function
Int.dec()
for decrementing values, butdec
alone could do the work.Similar solution is used in Jetpack Compose.
What do you think about this enhancement? Maby this will be too confusing?
Beta Was this translation helpful? Give feedback.
All reactions