Java BigDecimal to Double

Java BigDecimal to Double

In this post, we will see how to convert BigDecimal to Double in java.

Convert BigDecimal to Double in Java

You can simple use BigDecimal’s doubleValue() to convert BigDecimal to Double in java.

Output:

Double value: 22.2345

BigDecimal to double with 2 decimal places

If you want to restrict double to 2 decimal places, you can use BigDecimal’s setScale() method. You can use RoundMode to specify rounding behavior.

Output:

Double upto 2 decimal places: 2.33
Double upto 2 decimal places – RoundingMode.DOWN: 2.32
Double upto 2 decimal places – RoundingMode.UP: 2.33

That’s all about Java BigDecimal to Double.

Related Posts

  • Convert float to int in Python
    19 June

    Convert float to int in Python

    Table of ContentsUsing the int() function to convert float to int in PythonUsing the math module functions to convert float to int in PythonUsing ceil()Using trunc()Using floor Python provides several in-built functions and modules for datatype conversions. Floating-point numbers can be easily converted to integers using some of these in-built functions. This tutorial will discuss […]

  • Java Set to Array
    12 May

    Java Set to Array

    Table of Contents1. Using Java 8’s Stream2. Using toArray()3. Using toArray(IntFunction) [Java 11]4. Using System.arraycopy()5. Using Arrays.copyOf6. Using simple iteration7. Using Guava library7.1 Using FluentIterable7.2 Using Iterables In this post, we will learn java set to array conversion. There are many ways to convert set to an array. 1. Using Java 8’s Stream If you […]

  • Convert Date to LocalDate in java
    12 January

    Java Date to LocalDate

    Table of ContentsUsing toInstant() method of Date classUsing toInstant() method of Date classUsing java.sql.Date In this post, we will see how to convert Date to LocalDate in java. Sometimes, we may need to convert Date to new Java 8 APIs and vice versa. There are multiple ways to convert Date to LocalDate in java. Read […]

  • Convert LocalDate to Date in java
    11 January

    Java LocalDate to Date

    Table of ContentsUsing Instant objectUsing java.sql.Date In this post, we will see how to convert LocalDate to Date. Java 8 has introduced a lot of new APIs for Date and time. There can be many ways to convert Java LocalDateTime to date. Using Instant object You can convert LocalDate to Date using Instant object which […]

  • Convert LocalDateTime to Timestamp in java
    18 November

    Convert LocalDateTime to Timestamp in Java

    Table of ContentsLocalDateTimeTimestampConvert LocalDateTime to Timestamp In this post, we will how to convert LocalDateTime to Timestamp . Before learning how to convert localdatetime to timestamp, let us learn about LocalDateTime and Timestamp, and understand the importance of this conversion. LocalDateTime LocalDateTime was introcuded in Java 8. LocalDateTime can be imported time package: import java.time.LocalDateTime; […]

  • Java Stream List to Map
    26 April

    Java Stream List to Map

    Table of ContentsWhat happens in case of a duplicate key?What if you want specific Map such as TreeMap?Get multiMap with Collectors.groupingBy()Excercise In this post, we will see how to convert List to Map using Stream in java 8. Collectors’s toMap() can be used with stream to convert List to Map in java. Consider a class […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.