473,566 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

jhardman
3,406 Recognized Expert Specialist
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
1 1654
Luuk
1,047 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. SELECT TRY_CAST(X.A AS DECIMAL(12,2)) 
  2. FROM (
  3.     SELECT '2.345' as A
  4.     UNION ALL
  5.     SELECT '2,345'
  6.     ) AS X
  7.  
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

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

Similar topics

8
7121
by: LW Irving | last post by:
when I use the snippet below price = "$" + reader.ToString() + " to $" + reader.ToString(); the price is returned with 4 decimal places I thought I could do; reader.ToString("C") to format the string as currency and do away "$" + from the line
0
768
by: lianfe_ravago | last post by:
Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: ...
1
1903
by: Big E | last post by:
Here is my code below. I recieve this error when I run MyCommand.SelectCommand.ExecuteNonQuery() Thanks. Big E Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
1
2840
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate = request.QueryString("enddate") Line 20: Line 21: if cint(eventid) = "0" then
3
11739
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. The program uses ADO.NET . The following instruction: Me.cd_insertDataRecord.ExecuteNonQuery() throws this exception: ">>>ProcessDataRecord/ Exception: Type= System.FormatException Message: Input string was not in a correct format. StackTrace: at...
3
4620
by: Josh | last post by:
I am writing a program where the user inputs currency in US dollars. I want the program to only accept valid currency input, converting the string into the proper type of variable (double?), and to make sure there are no illegal characters entered so that it doesn't make an error. I basically want it to strip out any characters that aren't...
7
5168
by: M C | last post by:
Hi, This is a problem that has been haunting me for days and I've come to a complete dead-end. I'm using a objectdatasource to select and update a gridview control. Populating with select works fine but updating gives the "input string... " error. Any suggestions or links to a working sample. Let me know if anyone needs any code posted......
3
2037
by: Pieter Coucke | last post by:
Hi, When a user types a non numeric-value in a numeric column in a DataGridView, and he tries to leave the cell, he gets this "Input string was not in a correct format."-exception. Is there a (nice) way to get rid of this exception? And just put a "0" in the place? Or somehow trigger this single exception (does exceptions have a unique...
10
668
by: Badis | last post by:
Hi Guys, I'm trying to retrieve data defined as Numeric in Cache database and display it in a textbox but it's giving me this error: "Input string was not in a correct format" Cheers.
0
1631
by: RSH | last post by:
Hi, I have a situation where I am using a dataset from a SQL Query. SQL's DateTime is a "long date/time field" which includes the Date/Time. My fields need to be displayed in a short time format "08:00" instead of "1/1/1900 08:00 AM"? I can't alter the database table, I only want to change the displayed value. How do I either change the...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.