Why does Scala BigDecimal have a ZERO?

Easy to create:

object zero extends BigDecimal(java.math.BigDecimal.ZERO) 

I'm just wondering if this was an oversight or was there a conscious decision not to add this, and if so, then there are reasons why I should avoid the code above. Perhaps this is due to the MathContext ?

+6
source share
2 answers

I would think, because usually you do not need it. If in Java you need to enter something like

 BigDecimal b = new BigDecimal(1.23).add(BigDecimal.ZERO); 

in Scala, there are numerical conversions that mean you can write

 val b = BigDecimal(1.23) + 0 

You can also write it simply as BigDecimal(0) . If you create an instance of this file, you may want to cache it as a named value (as for any other number), but you usually do not need it, and I think this simplifies the API if you delete special cases that you must remember.

+4
source

If I had to guess, because the expected way to get this value would be as follows:

 val zero: BigDecimal = 0 
+14
source

Source: https://habr.com/ru/post/909295/


All Articles