# bigdecimal

## How to handle very large numbers in Scala (BigInt, BigDecimal)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.6, “Handling Very Large Numbers in Scala.”

## Problem

You’re writing a Scala application and need to use very large integer or decimal numbers.

## Solution

Use the Scala `BigInt` and `BigDecimal` classes. You can create a `BigInt`:

## Scala: How to parse a number from a String

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.1, “Parsing a Number from a String.”

## Problem

You want to convert a `String` to one of Scala’s numeric types (`Byte`, `Double`, `Int`, `Float`, `Long`, `Short`).

## How to use BigInt and BigDecimal when you need very large numbers in Scala

Scala FAQ: I’m writing an application and I need to use very large integer or decimal (floating-point) numbers; what’s the best approach?

## Solution

Use the Scala `BigInt` and `BigDecimal` classes. You can create a `BigInt`:

```scala> var b = BigInt(1234567890)
b: scala.math.BigInt = 1234567890```

or a `BigDecimal`: