RSS

Calculation of two strings – return Currentcy Format Amount

01 Mar

Hi folks,

Here is the snippet of code to calculate the two given strings values and returns the calculated value in the currentcy format amount.

public static void main(String[] args) {
String amount = “1000.90”;
String feeAmt = “100.30”;
String totalAmount = getCalculatedValue(amount,feeAmt);
System.out.println(“Total Amount –> “+totalAmount);
}

/**
* @param amount
* @param feeAmt
* @return String
*/
private static String getCalculatedValue(String amount, String feeAmt) {
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
double calAmount = Double.parseDouble(amount) + Double.parseDouble(feeAmt);
return String.valueOf(currencyFormatter.format(calAmount));
}

//Total Amount –> $1,101.20

Happy Coding!.

Get glued to know more updates.

Have a nice day đŸ™‚

Advertisements
 
2 Comments

Posted by on March 1, 2013 in Uncategorized

 

2 responses to “Calculation of two strings – return Currentcy Format Amount

  1. Sreenivas

    March 1, 2013 at 12:58 pm

    Its really useful blog. Thank you.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: