This method is used to convert a dollar amount to cents given String as input and returns a long value - Java java.lang

Java examples for java.lang:double Format

Description

This method is used to convert a dollar amount to cents given String as input and returns a long value

Demo Code


//package com.java2s;

public class Main {
    /**//from w  w  w .j  a  va2s  . c  om
     * This method is used to convert a dollar amount to cents given String as
     * input and returns a long value
     * 
     * @param amount
     * @return
     */
    public static long dollarToCentsRtnLong(String amount) {

        double doubleVal = Double.parseDouble(amount);
        long longVal = (long) (doubleVal * 100);
        return ((Long) longVal);
    }
}

Related Tutorials