Home » Java » Java Reference

# Java BigDecimal Class Methods

Java BigDecimal class has the following built-in methods.

Method | Description |
---|---|

abs() | It is used to get a BigDecimal that holds the absolute value of this BigDecimal. |

add() | It is used to get a BigDecimal that holds the value added this BigDecimal with the given BigDecimal and its scale is calculated by using max([this BigDecimal.scale()] , [BigDecimal val.scale()]). |

byteValueExact() | It is used to convert a BigDecimal to exact byte value. |

compareTo() | It is used to compare this BigDecimal object to the given object. |

divideAndRemainder() | It is used to get an array of BigDecimal of two elements (the quotient and the remainder), it first divides by using divideToIntegralValue() followed by the result of remainder on the two values of "BigDecimal" type manipulated. |

divideToIntegralValue() | It is used to get a BigDecimal and its value is the non-fractional part of the quotient is calculated by using (this BigDecimal/ BigDecimal divsr) and the scale is calculated by using (this BigDecimal.scale() – BigDecimal divsr.scale()). |

doubleValue() | It is used to convert a BigDecimal to a double value. |

equals() | It is used to check whether this BigDecimal and the given object are equal or not. |

floatValue() | It is used to convert a BigDecimal to a float value. |

hashCode() | It is used to get the hash code value for this BigDecimal object. |

intValue() | It is used to convert a BigDecimal to an integer. |

intValueExact() | It is used to convert this BigDecimal into an exact integer value. |

longValue() | It is used to convert this BigDecimal to a long value. |

longValueExact() | It is used to convert this BigDecimal to an exact long value. |

max() | It is used to get the greatest value of (this BigDecimal) and the given (BigDecimal ob). |

min() | It is used to get the least value of (this BigDecimal) and the given (BigDecimal ob). |

movePointLeft() | It is used to get a BigDecimal which is similar to this BigDecimal with the decimal point shifted to the given number of places to the left side. |

movePointRight() | It is used to get a BigDecimal which is similar to this BigDecimal with the decimal point shifted to the given number of places to the right side. |

multiply() | It is used get a BigDecimal that holds the value multiplied this BigDecimal by the given BigDecimal and its scale is calculated by using ([this BigDecimal.scale()] * [BigDecimal m_val.scale()]). |

negate() | It is used to get a negation of this BigDecimal and its scale is non-negative. |

plus() | It is used to get the value with (+) representation of this BigDecimal. |

pow() | It is used to calculate the value of this BigDecimal is raised to the power of the given parameter (x) (i.e. [(this BigDecimal) pow (x)]). |

precision() | It is used to get the precision of this BigDecimal object and we all know the term precision is the number of digits represented in the un-scaled value. |

remainder() | It is used to calculate the remainder by using ([this BigDecimal] % divsr). |

round() | It is used to get a rounded BigDecimal based on the given MathContext setting when the precision value is not equal to 0 otherwise there is no effect of rounding when precision value is equal to 0. |

scale() | It is used to get the scale of this BigDecimal object. |

setScale() | It is used to set the new scale with the given scale of this BigDecimal object. |

scaleByPowerOfTen() | It is used to get a BigDecimal whose value is calculated by using [(this BigDecimal) * 10 pow(number)]. |

shortValueExact() | It is used to convert this BigDecimal to an exact short value. |

signum() | It is used to get the signum (sign number) function of this BigDecimal object. |

stripTrailingZeros() | It is used to get a BigDecimal that is equivalent to this BigDecimal but without any Trailing zeros. |

subtract() | It is used to get a BigDecimal that holds the value subtracted the given parameter (val) from this BigDecimal. |

toBigInteger() | It is used to convert this BigDecimal object value into a BigInteger object value and the decimal part will be skipped during conversion of this BigDecimal. |

toBigIntegerExact() | It is used to convert this BigDecimal into the exact BigInteger value and it will throw an exception when this BigDecimal holds some fractional part that is other than 0. |

toEngineeringString() | It is used to represent string denotation of this BigDecimal with the help of engineering notation when an exponent is required to denote BigDecimal as a String. |

toPlainString() | It is used to represent string denotation of this BigDecimal without the help of any notation and no exponent is required to denote BigDecimal as a String. |

toString() | It is used to represent string denotation of this BigDecimal with the help of scientific notation when an exponent field is required to denote BigDecimal as String. |

ulp() | It is used to get the size of an ulp of this BigDecimal. |

unscaledValue() | It is used to calculate the unscaled value by using the formula ([this BigDecimal] * 10 pow [this BigDecimal.scale()] ) of this BigDecimal as a BigInteger. |

valueOf() | It is used to convert the given double value into a BigDecimal. |

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.