# Java.math.MathContext Class

## Introduction

The java.math.MathContext class provides immutable objects which encapsulate the context settings and describes certain rules for numerical operators, such as those implemented by the BigDecimal class.

The base-independent settings are −

• precision − the number of digits to be used for an operation; results are rounded to this precision.

• roundingMode − a RoundingMode object which specifies the algorithm to be used for rounding.

## Class declaration

Following is the declaration for java.math.MathContext class −

```public final class MathContext
extends Object
implements Serializable
```

## Field

Following are the fields for java.math.MathContext class −

• static MathContext DECIMAL128 − A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.

• static MathContext DECIMAL32 − A MathContext object with a precision setting matching the IEEE 754R Decimal32 format, 7 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.

• static MathContext DECIMAL64 − A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.

• static MathContext UNLIMITED − A MathContext object whose settings have the values required for unlimited precision arithmetic.

## Class constructors

Sr.No. Constructor & Description
1

MathContext(int setPrecision)

This constructor, constructs a new MathContext with the specified precision and the HALF_UP rounding mode.

2

MathContext(int setPrecision, RoundingMode setRoundingMode)

This constructor, constructs a new MathContext with a specified precision and rounding mode.

3

MathContext(String val)

This constructor, constructs a new MathContext from a string.

## Class methods

Sr.No. Method & Description
1 boolean equals(Object x)

This method compares this MathContext with the specified Object for equality.

2 int getPrecision()

This method returns the precision setting.

3 RoundingMode getRoundingMode()

This method returns the roundingMode setting.

4 int hashCode()

This method returns the hash code for this MathContext.

5 String toString()

This method returns the string representation of this MathContext.
{"ft_lang_label":"__label__en","ft_lang_prob":0.52623373,"math_prob":0.5131672,"size":2188,"snap":"2020-10-2020-16","text_gpt3_token_len":454,"char_repetition_ratio":0.18818681,"word_repetition_ratio":0.19155844,"special_character_ratio":0.2047532,"punctuation_ratio":0.115606934,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98753625,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-03T08:40:36Z\",\"WARC-Record-ID\":\"<urn:uuid:ebbfb6cc-fb87-412f-b8cc-8f830b7c2673>\",\"Content-Length\":\"21800\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e11761ce-7dc5-4451-abfa-3309bcd60b96>\",\"WARC-Concurrent-To\":\"<urn:uuid:a577d1bf-d1a4-4d0e-abcb-c6a3bde8c9c1>\",\"WARC-IP-Address\":\"72.21.91.42\",\"WARC-Target-URI\":\"http://www.tutorialspoint.com/java/math/java_math_mathcontext.htm\",\"WARC-Payload-Digest\":\"sha1:BQ5IAKRUD4ZRJJQQGH67BBGNFHNLQCEI\",\"WARC-Block-Digest\":\"sha1:EBGAGYZLNVBFNTNJTLA2GP2RA5DEUTXZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370510352.43_warc_CC-MAIN-20200403061648-20200403091648-00077.warc.gz\"}"}