Here you can find the source of formatDoubleToTwoDecimalString(double number)
public static String formatDoubleToTwoDecimalString(double number)
//package com.java2s; public class Main { public static String formatDoubleToTwoDecimalString(double number) { double theNumber = calculateRechargeAmountInRandsFor(number); return twoDecimalDoubleFormatter(theNumber); }/*from w w w . j av a2 s. co m*/ public static double calculateRechargeAmountInRandsFor(double reading) { double amount = tariff() * reading; double vat = amount / 14; return amount + (vat * 2); } public static String twoDecimalDoubleFormatter(double number) { return String.format("%.2f", number); } public static double tariff() { //in the future might get it from some place server? return 0.838; //in rands this equal 1kw } }