473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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

jhardman
3,406 Expert 2GB
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 1643
Luuk
1,047 Expert 1GB
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
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...
0
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...
1
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...
1
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 =...
3
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/...
3
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...
7
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...
3
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...
10
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
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.