get Currency value from String - Java java.lang

Java examples for java.lang:String Parse

Description

get Currency value from String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String value = "java2s.com";
        System.out.println(getCurrency(value));
    }/*from w w w  .jav  a  2  s.c o  m*/

    public static double getCurrency(String value) {
        return getCurrency(value, 0D);
    }

    public static double getCurrency(String value, double defaultValue) {
        try {
            return Double.parseDouble(value.replaceAll("[?,]", ""));
        } catch (Exception ex) {
            return defaultValue;
        }
    }
}

Related Tutorials