I am reading in a pipe delimited file and need to check whether a column is a valid currency (i.e. it must follow a format as xxxxx.xx , so a maximum of two digits after the decimal although it is not necessary to have any digits after the decimal). How would I go about doing this in C#?
Share
Try converting your value to a currency, like this:
validwill then be either true if TryParse could parse it as a currency. This is by far a better option than using regular expressions.To get the fraction (decimals) of your value, just convert it to an int and subtract it from the original value, like:
fractionwill then contain decimals and you can do whatever you like with them.