ADVERTISEMENT
ADVERTISEMENT

Java BigDecimal toString() Method with Example

BigDecimal Class toString() method: Here, we are going to learn about the toString() method of BigDecimal Class with its syntax and example.
Submitted by Preeti Jain, on May 08, 2020

BigDecimal Class toString() method

  • toString() method is available in java.math package.
  • toString() method 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.
  • toString() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • toString() method does not throw an exception at the time of string representation.

Syntax:

    public String toString();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is String, it returns string denotation of this BigDecimal.

Example:

// Java program to demonstrate the example 
// of String toString() method of BigDecimal

import java.math.*;

public class ToStringOfBD {
    public static void main(String args[]) {
        // Initializes a variables -  
        // String type
        String str = "12642E5";

        // Initializes a BigDecimal object  
        BigDecimal b_dec = new BigDecimal(str);

        // represents this BigDecimal b_dec value as
        // a String by using the scientific notation
        String str_conv = b_dec.toString();
        System.out.println("b_dec.toString(): " + str_conv);
    }
}

Output

b_dec.toString(): 1.2642E+9
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.