Doc Holiday Doc Holiday - 1 year ago 139
Java Question

Trim Double to 2 decimal places

should be an easy one. I originally was gonna do this in javascript but have to do it prior to setting to the form in my handler page. Anyway I need to make these values have 2 decimal places. Ex 219333.5888888 needs to be 219333.58. Is there a trim function or something?

form.setUnitRepairCost(Double.toString(jobPlanBean.getUnitTotalCost())); //UNIT REPAIR COST
form.setUnitMaterialCost(Double.toString(jobPlanBean.getUnitTotalMaterialCost())); //UNIT MATERIAL COST

Answer Source

here is the simple example to format the decimal value

import java.text.*;

public class DecimalPlaces {

    public static void main(String[] args) {

        double d = 1.234567;
        DecimalFormat df = new DecimalFormat("#.##");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download