Click here to Skip to main content
15,607,737 members
Please Sign up or sign in to vote.
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;
Updated 14-Nov-22 19:18pm
Graeme_Grant 14-Nov-22 23:13pm    
strip the currency symbols, then you can add the numbers

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.
Share this answer
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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900