Java BigDecimal negate() method

The negate() method of java BigDecimal class is used to obtain a BigDecimal whose value is the negated value (-this) of the BigDecimal with which it is used.

Syntax:

Parameter:

mc: the context to use.

Exception:

ArithmeticException- if the result is inexact but the rounding mode is UNNECESSARY, the it throws exception:

Returns:

It returns -this(negated BigDecimal value), rounded as necessary.

Example 1

Test it Now

Output:

Negated value of 5656 is =  -5656

Example 2

Test it Now

Output:

Negated value of  -152207  is =  152207

Example 3

Test it Now

Output:

Negated value of  -18.5414 rounded by 4  is =  18.54

Example 4

Test it Now

Output:

Negated value of  -178901456.68431 rounded by 16  is =  178901456.68431

Next TopicJava BigDecimal




Latest Courses