Click here to Skip to main content
15,885,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on an app that uses a 3rd party csv file as input and assigned the various values to strings. The dollar amounts are in the following format . .

if a monetary amount is a negative it is, for example, ($7685)

if the monitary amount is a positive, it is $7685

I will need to convert to a double (to use in calculations). Before I start trying to parse this and convert, are there any methods that would make my life easier in parsing/converting this?

I appreciate all suggestions.
Posted

1 solution

You may need to remove '$', and then you can use double.Parse(string, System.Globalization.NumberStyles) with System.Globalization.NumberStyle.AllowParentheses:
http://msdn.microsoft.com/en-us/library/7yd1h1be%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.numberstyles%28v=vs.110%29.aspx[^].

This weird style is funny; it looks like it was invented by finance morons who did not properly learn elementary mathematics at school and consider negative numbers as something exotic. As we know from the history of mathematics, negative numbers were embraced quite late.

—SA
 
Share this answer
 
Comments
Ron Beyer 26-Jan-14 21:15pm    
Even the concept of zero was adopted quite late, however there is a good reason finance "morons" use parens rather than a - sign. The reason is that when doing ledger sheets, debits are positive, credits are positive, and the balance is also positive. In order to quickly scan a very big list for a negative balance, its put in parenthesis to make it stand out more. In handwriting, a small - can be hard to spot quickly.

With the advent of computers its just a hold-over from "the old way".

+5 :)
Sergey Alexandrovich Kryukov 26-Jan-14 21:29pm    
Thank you, Ron.

I do understand the reason you explained, thank you. The '-' sign is probably not the best option, but it belongs to common culture; actually, sub-cultural or narrow "professional" languages is a kind of evil. (Do you know that this is not the minus sign but a "dash"? Unicode minus sign is different, yet another reason for further confusions.) However, () is also not the most visible thing, too.

It's funny to observe all those hold-overs. You are quite right about the zero. Unfortunately, many individuals did not really embraced zero, negatives and many other common notions even now, it can be clearly seen indirectly. For example, the trend to enumerate things not from 0, but from 1 (actually, a complication) is not just the matter of convention. This is really the cultural consequence of considering zero as something best avoided; it came to many people's psychology, throw history. Do you know the рecapitulation theory principle ("ontogeny recapitulates phylogeny", http://en.wikipedia.org/wiki/Recapitulation_theory)? Same thing can be seen in culture...

—SA
JOHNNYDEMICHAEL 27-Jan-14 8:24am    
I think I entered my comment in wrong area . . .

Great . . . thanks! Excellent commentary!

It was meant for Sergey.
Sergey Alexandrovich Kryukov 27-Jan-14 11:08am    
This comment is entered exactly where it belongs.
You are very welcome.
Good luck, call again.
—SA

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