By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

can't format my decimal as currency - input string was not in correct format

Expert 2.5K+
P: 3,405
i have decimals coming in from a SQL Server db, and displaying them without converting them works.
Expand|Select|Wrap|Line Numbers
  1. response.write ("<td>"& i & "</td>")
I can add and subtract without any errors
Expand|Select|Wrap|Line Numbers
  1. response.write ("<td>"& i+3.5 & "</td>")
  2. response.write ("<td>"& i+0.0 & "</td>")
and i can use that last to trim off the extra decimals, so that is nice.
I can use the toString() function without arguments
Expand|Select|Wrap|Line Numbers
  1. response.write ("<td>"& i.ToString() & "</td>")
and this works but doesn't give me the format I want. If I try to format as currency:
Expand|Select|Wrap|Line Numbers
  1. response.write ("<td>"& i.ToString("C") & "</td>")
I get an error "Input string was not in a correct format". Isn't that how toString() is supposed to work? What am I doing wrong?
Jan 24 '19 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,035
Expand|Select|Wrap|Line Numbers
  2. FROM (
  3.     SELECT '2.345' as A
  4.     UNION ALL
  5.     SELECT '2,345'
  6.     ) AS X
Use TRY_CAST in SQL server, so you KNOW that the numbers are in a correct format. (NULL is returned if they are not in a correct format)
Jan 27 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.