BigDecimal ulp() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.math.BigDecimal.ulp() is an inbuilt method in Java that returns the size of an ulp(unit in the last place) of this BigDecimal. An ulp of a nonzero BigDecimal value is defined as the positive distance between this value and the BigDecimal value next larger in magnitude with the same number of digits. An ulp of a zero value is numerically equal to 1 with the scale of this. The result is stored with the same scale as this so the result for zero and nonzero values is equal to [1, this.scale()]. Syntax: public BigDecimal ulp() Parameter: The method does not accept any parameter. Return value: This method returns the size of an ulp of BigDecimal. Examples: Input: 4.25 Output: 0.01 Input: 1789 Output: 1 Below programs illustrates the above mentioned method: Program 1: Java // Program to illustrate the ulp() method of BigDecimal import java.math.*; public class gfg { public static void main(String[] args) { // Assigning BigDecimal object BigDecimal b1 = new BigDecimal("1789"); BigDecimal b2 = new BigDecimal("4.25"); // Assigning ulp value of BigDecimal object b1, b2 to b3, b4 BigDecimal b3 = b1.ulp(); BigDecimal b4 = b2.ulp(); // Printing b3, b4 values System.out.println("ULP value of " + b1 + " is " + b3); System.out.println("ULP value of " + b2 + " is " + b4); } } Output: ULP value of 1789 is 1 ULP value of 4.25 is 0.01 Program 2: Java // Program to illustrate the ulp() method of BigDecimal import java.math.*; public class gfg { public static void main(String[] args) { // Assigning BigDecimal object BigDecimal b1 = new BigDecimal("78645"); BigDecimal b2 = new BigDecimal("4.252547"); // Assign ulp value of BigDecimal object b1, b2 to b3, b4 BigDecimal b3 = b1.ulp(); BigDecimal b4 = b2.ulp(); // Printing b3, b4 values System.out.println("ULP value of " + b1 + " is " + b3); System.out.println("ULP value of " + b2 + " is " + b4); } } Output: ULP value of 78645 is 1 ULP value of 4.252547 is 0.000001 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#ulp() Comment More infoAdvertise with us Next Article BigDecimal ulp() Method in Java T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-Functions java-math Java-BigDecimal Java-math-package +2 More Practice Tags : JavaMisc Similar Reads BigDecimal min() Method in Java The java.math.BigDecimal.min(BigDecimal val) method in Java is used to compare two BigDecimal values and return the minimum of the two. Syntax: public BigDecimal min(BigDecimal val) Parameters: The function accepts a BigDecimal object val as parameter whose value is compared with that of this BigDec 2 min read BigDecimal valueOf() Method in Java java.math.BigDecimal.valueOf(long val) is an inbuilt method in Java that translates a long value into a BigDecimal value with a scale of zero. It allows us, the reuse of frequently used BigDecimal values and hence this "static factory method" is provided in preference to a (long) constructor. Packag 3 min read BigDecimal max() Method in Java The java.math.BigDecimal.max(BigDecimal val) method in Java is used to compare two BigDecimal values and return the maximum of the two. This is opposite to BigDecimal max() method in Java. Syntax: public BigDecimal max(BigDecimal val) Parameters: The function accepts a BigDecimal object val as param 2 min read BigDecimal precision() Method in Java The java.math.BigDecimal.precision() method returns the precision of this BigDecimal. The precision refers to the number of digits in the unscaled value. Syntax: public int precision() Parameters: This method does not accept any parameters. Return Value: This method returns an integer which denotes 2 min read BigDecimal intValue() Method in Java The java.math.BigDecimal.intValue() is an in-built function which converts this BigDecimal to an integer value. This function discards any fractional part of this BigDecimal. If the result of the conversion is too big to be represented as an integer value, the function returns only the lower-order 3 2 min read BigDecimal longValue() Method in Java The java.math.BigDecimal.longValue() is an in-built function which converts this BigDecimal to a long value. This function discards any fractional part of this BigDecimal. The function returns only the lower-order 64 bits when the result of the conversion is too big to be represented as a long value 2 min read BigDecimal toBigInteger() Method in Java The java.math.BigDecimal.toBigInteger() is an inbuilt method in java that converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long. Any fractional part of this BigDecimal will be discarded. This conversion can lose information a 2 min read BigDecimal shortValueExact() Method in Java The java.math.BigDecimal.shortValueExact() is an inbuilt method in java that converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown. Syntax: public s 2 min read BigDecimal doubleValue() Method in Java The java.math.BigDecimal.doubleValue() is an in-built function which converts the BigDecimal object to a double. This function converts the BigDecimal to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate or according to the passed object, if its magnitude is too big to be represent 2 min read BigDecimal stripTrailingZeros() Method in Java The java.math.BigDecimal.stripTrailingZeros() is an inbuilt method in Java that returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. So basically the function trims off the trailing zero from the BigDecimal value. Syntax: public Big 2 min read Like