### New To Java

#### BigDecimal Range

Hi Please let me know if there is any range for BigDecimal? If so what is the range? Thanks in advance.

Note: This thread was originally posted in the [Swing|http://forums.sun.com/forum.jspa?forumID=57] forum, but moved to this forum for closer topic alignment.

The range of BigDecimal is effectively only limited by available memory (and the fact that arrays in Java are indexed by int variables, but you'll likely hit the other restriction earlier). For pretty much all uses, the range is effectively unlimited.

JoachimSauer wrote: For pretty much all uses, the range is effectively unlimited. Would they be accurate up to say 1^(-1,000,000)? I've yet to reach such limits but from my own calculations it is feasible that I may need them to be that accurate. Maybe = |

BigDecimal is as accurate as documented across its whole range (it's an arbitrary precision data type). The problem is not that it becomes inaccurate at some size, but that it isn't able to represent numbers outside a certain range.

mrwobbles wrote: JoachimSauer wrote: For pretty much all uses, the range is effectively unlimited. Would they be accurate up to say 1^(-1,000,000)? One raised to the power negative one million? System.out.println(Math.pow(1, -1000000)); ... 1.0

jverd wrote: mrwobbles wrote: JoachimSauer wrote: For pretty much all uses, the range is effectively unlimited. Would they be accurate up to say 1^(-1,000,000)? One raised to the power negative one million? System.out.println(Math.pow(1, -1000000)); ... 1.0 I think I might have missed a 0 there... So the maximum scale is the maximum 32 bit integer? I think that will be enough but just for ***** and giggles say I needed a scale bigger than that, what's my best option?

System.out.println(Math.pow(1, -1000000)); ... 1.0 Spoilsport

So the maximum scale is the maximum 32 bit integer? That's an absolutely colossal number - do you realise how big it is?

mrwobbles wrote: jverd wrote: mrwobbles wrote: JoachimSauer wrote: For pretty much all uses, the range is effectively unlimited. Would they be accurate up to say 1^(-1,000,000)? One raised to the power negative one million? System.out.println(Math.pow(1, -1000000)); ... 1.0 I think I might have missed a 0 there... So the maximum scale is the maximum 32 bit integer? I think that will be enough but just for ***** and giggles say I needed a scale bigger than that, what's my best option? Find a different universe

mrwobbles wrote: I think that will be enough but just for kicks and giggles say I needed a scale bigger than that, what's my best option? Work with logarithms.

roger.bagnall wrote: So the maximum scale is the maximum 32 bit integer? That's an absolutely colossal number - do you realise how big it is? 2,147,483,647 I think. Which was the starting budget if you cheated in SimCity 2000. Compared to the scale of the combined national and private debt of the [USA |http://www.usdebtclock.org/] it is small. Maybe that says more about that debt than the size of the number. In comparison to infinity it is next to nothing, but I wanted to know if it was possible to represent a number that large in Java. I guess not.

mrwobbles wrote: 2,147,483,647 I think. Uhm, check Integer.MAX_VALUE

PhHein wrote: mrwobbles wrote: 2,147,483,647 I think. Uhm, check Integer.MAX_VALUE public class run { public static void main(String[] args) { System.out.print(Integer.MAX_VALUE); } }

Exactly, so you are way off.