ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Java BigDecimal toEngineeringString() Method with Example

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

BigDecimal Class toEngineeringString() method

  • toEngineeringString() method is available in java.math package.
  • toEngineeringString() method 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.
  • toEngineeringString() 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.
  • toEngineeringString() method does not throw an exception at the time of representing this BigDecimal as a String.

Syntax:

    public String toEngineeringString();

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 object with the help of engineering notation.

Example:

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

import java.math.*;

public class ToEngineeringStringOfBD {
    public static void main(String args[]) {
        // Initializes a variable -  
        // String type
        String str = "12E+5";

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

        // By using toEngineeringString() method is 
        // used to represent this BigDecimal b_dec as
        // a String by using the engineering notation
        String str_conv = b_dec.toEngineeringString();
        System.out.println("b_dec.toEngineeringString(): " + str_conv);
    }
}

Output

b_dec.toEngineeringString(): 1.2E+6
ADVERTISEMENT




Comments and Discussions

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.