15,607,737 members
1.00/5 (1 vote)
See more:
Hi there,

I want to calculate two numeric values which contains , ₹ sign.

For Example :

sum = ₹50,000 + ₹25,000;

It is giving me incorrect format error.

What I have tried:

int one = ₹50,000;
int two = ₹25,000;

result = one + two;
Posted
Updated 14-Nov-22 19:18pm
Graeme_Grant 14-Nov-22 23:13pm
strip the currency symbols, then you can add the numbers

## Solution 1

You can't do math like that: what if the two values were in different currencies?
`sum = ₹50,000 + \$25,000;`
What should the result be? Dollars? Yen? Rupees? What was the exchange rate? What kind of exchange rate should be used - International, or Tourist? When was the exchange to be done? Are there any fees to be deducted?

You can't include currency symbols in numbers when you write code: instead you make your code work with a particular currency throughout, and then convert other currencies into that when they are entered, using whatever exchange rate is appropriate. You then either apply your chosen currency symbol when you output values, or convert that to an appropriate amount of the user's currency.

And you probably shouldn't be using `int` variable to store any currency: one rupee is made of 100 paise, so you need to use a datatype that allows for that - and `decimal` is the most appropriate.

Nikhil Yogi 15-Nov-22 3:09am
Thanks for the reply! After posting on this forum, I tried this C# function Replace() and it worked.