Java.math.MathContext Class - Java.math Package

What is Java math MathContext Class?

Introduction

The java.math.MathContext magnificence gives immutable items which encapsulate the context settings and describes certain rules for numerical operators, including those carried out through the BigDecimal class.

The base-impartial settings are −

  • Precision − the wide variety of digits to be used for an operation; results are rounded to this precision.
  • Rounding Mode − a RoundingMode object which specifies the algorithm for use for rounding.

Class Declaration

Following is the assertion for java.math.MathContext class –

Field

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

  • static MathContext DECIMAL128 − A MathContext item with a precision putting matching the IEEE 754R Decimal128 layout, 34 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.
  • static MathContext DECIMAL32 − A MathContext item with a precision placing matching the IEEE 754R Decimal32 layout, 7 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.
  • static MathContext DECIMAL64 − A MathContext item with a precision setting matching the IEEE 754R Decimal64 layout, 16 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.
  • Static MathContext unlimited − A MathContext item whose settings have the values required for unlimited precision arithmetic.

Class constructors

S.N.

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

S.N.

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

Rounding Mode 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.


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java.math Package Topics