GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — Java.math.MathContext Class

Java.math package tutorial
  • Java.math - Home
  • Java.math - BigDecimal
  • Java.math - BigInteger
  • Java.math - MathContext
  • Java.math - Enumerations
  • Java.math - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

Java.math.MathContext Class



Previous
Quiz
Next

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.

Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.