- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Negate a BigDecimal value in Java
Use the negate() method to negate a BigDecimal value in Java. The method returns a BigDecimal whose value is (-this), and whose scale is this.scale().
The following is an example −
Example
import java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { BigDecimal val1 = new BigDecimal("37578975587"); BigDecimal val2 = new BigDecimal("62567875598"); System.out.println("Value 1 : "+val1); System.out.println("Value 2 : "+val2); // division val1 = val2.negate(); System.out.println("Result (Negation) = "+val1); } }
Output
Value 1 : 37578975587 Value 2 : 62567875598 Result (Negation) = -62567875598
Let us see another example −
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigDecimal bg1, bg2; bg1 = new BigDecimal("68.99898"); bg2 = bg1.negate(); String str = "Negated value of " + bg1 + " is "+ bg2; System.out.println( str ); } }
Output
Negated value of 68.99898 is -68.99898
- Related Articles
- Truncate BigDecimal value in Java
- Negate a BigInteger in Java
- Multiply one BigDecimal to another BigDecimal in Java
- Subtract one BigDecimal from another BigDecimal in Java
- Java Program to create a BigDecimal from a string type value
- Create a BigDecimal via string in Java
- Java Program to divide one BigDecimal from another BigDecimal
- Create BigDecimal Values via a long in Java
- Math operations for BigDecimal in Java
- Working with BigDecimal values in Java
- Compare BigDecimal movePointRight and scaleByPowerOfTen in Java
- Java Program to round a double passed to BigDecimal
- negate function in C++ STL
- How to negate a predicate function in JavaScript?
- Negate an if Condition in a Bash Script in Linux

Advertisements