Search
 
SCRIPT & CODE EXAMPLE
 

CSS

java round double to 2 decimals

double roundOff = Math.round(a * 100.0) / 100.0;
// Or
double roundOff = (double) Math.round(a * 100) / 100;
// both have the same output.
Comment

round off java 2 decimal places

class round{
    public static void main(String args[]){

    double a = 123.13698;
    double roundOff = Math.round(a*100)/100;

    System.out.println(roundOff);
}
}
Comment

how to round double to 2 decimal places java

// calling the function round
round(200.3456, 2);

// Include this function in your class
public static double round(double value, int places) {
    if (places < 0) throw new IllegalArgumentException();

    BigDecimal bd = BigDecimal.valueOf(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}
Comment

round the value of 2 decimals in java

class round{
    public static void main(String args[]){

    double a = 123.13698;
    double roundOff = Math.round(a*100)/100; //put attention to the parenthesis.

    System.out.println(roundOff);
}
}
Comment

round decimals in java string

package com.mkyong.math.rounding;

public class StringFormatExample {

  public static void main(String[] args) {

      double input = 1205.6358;

      System.out.println("salary : " + input);

      // round half-up, no way control
      // 1205.64
      System.out.println("salary : " + String.format("%.2f", input));

      // 1205.64
      System.out.format("salary : %.2f", input);

  }

}
Comment

PREVIOUS NEXT
Code Example
Css :: crop image in div 
Css :: php executable not found. install php 7 and add it to your path 
Css :: scale down image css 
Css :: backdrop filter css 
Css :: make clicks pass through element css html 
Css :: css flexbox syntax 
Css :: how make button which is fixed even after i scroll 
Css :: background css 
Css :: cs cirlce 
Css :: mixin parameters 
Css :: line icon 
Css :: scss darken 
Css :: css focus 
Css :: add .css to CKEDITOR 
Css :: firefox-scroll-css 
Css :: css make div one line 
Css :: css multiple classes 
Css :: sticky header not working chrome 
Css :: style inline css hover 
Css :: unhover animation 
Css :: css border top linear gradient 
Css :: css offset border 
Css :: box sizing css 
Css :: before and after pseudo selectors 
Css :: how to add grow effect animation button in css 
Css :: To make multiple equal width buttons occupy container width 
Css :: javafx change image on hover 
Css :: css icon 
Css :: font size clamp generator 
Css :: align svg and text inside button 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =