Java examples for java.lang:double Format
This method is used to convert a dollar amount to cents given double as input
//package com.java2s; public class Main { /**/*from w ww .j a v a 2 s.co m*/ * This method is used to convert a dollar amount to cents given double as * input * * @param amount * @return */ public static long dollarToCents(double amount) { return (long) (amount * 100); } /** * This method is used to convert a dollar amount to cents given String as * input * * @param amount * @return */ public static String dollarToCents(String amount) { double doubleVal = Double.parseDouble(amount); long longVal = (long) (doubleVal * 100); return ((Long) longVal).toString(); } }