473,387 Members | 1,456 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,387 software developers and data experts.

saving decimal value

Hello

I'm developing a project by using access database and there is a
table(Table1) and it has a field(ml_mik) this is the decimal field.

I'm taking a value from windows form as a decimal variable(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3
or 12.3...

I'm using ADO.NET for processes in the database.

How can I accomplish this error? How can I save 12,3 value in the database?

Thanks for your helps.


Nov 17 '05 #1
3 6487
Hi Brenny,
you need to make sure that if you are parsing user data then you pass in
the Culture in which the data has been formatted so that it is parsed
correctly. For example if you enter an number like 123.45 then if you parse
that as an EN-US culture then the number will be interpretted as 123.45 but
if you parse it as a German format i.e. DE-DE then it will be 12345

For example:

//get the number 123.45
string decimalNumber = this.textBox1.Text;

//parse this as a EN-US culture -> it will be stored in dEnUs as 123.45
decimal dEnUs = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("en-us"));

//parse this as a DE-DE culture it will be parse as 12345
decimal dDeDe = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("de-de"));
After you have parsed the value correctly through the GUI it should be
stored correctly in your database.

Hope that helps
Mark R Dawson.
"Brenny" wrote:
Hello

I'm developing a project by using access database and there is a
table(Table1) and it has a field(ml_mik) this is the decimal field.

I'm taking a value from windows form as a decimal variable(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3
or 12.3...

I'm using ADO.NET for processes in the database.

How can I accomplish this error? How can I save 12,3 value in the database?

Thanks for your helps.



Nov 17 '05 #2
"Brenny" <br***********@gmail.com> ha scritto nel messaggio
news:uZ**************@TK2MSFTNGP10.phx.gbl...

I'm taking a value from windows form as a decimal variable
How?
The variable is well valued?
(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3 or 12.3...
How do you pass the variable?
Is this a string, so that it is "converted"?
How can I accomplish this error? How can I save 12,3 value in the

database?

Using the right data type for variables and the conversion function
according on the tipe of separator you want to use (localized or ".").

--
Reporting tool: http://www.neodatatype.net
Nov 17 '05 #3
Thanks Mark.

//get the number 123.45
string decimalNumber = this.textBox1.Text;

//parse this as a EN-US culture -> it will be stored in dEnUs as 123.45
decimal dEnUs = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("en-us"));

After this code,123.45 is saved as 12345

What are database field's attributes?

If database field's value is currency, I can hold 123.45 as 123.45 but If I
hold this number as decimal, I can't hold as a decimal.

Access database I'm using is Turkish.. Can error occur because of this?.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
3
by: jbauer | last post by:
I was interested in playing around with Decimal and subclassing it. For example, if I wanted a special class to permit floats to be automatically converted to strings. from decimal import...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
3
by: corear | last post by:
I have a new case tracking system. The cases table has these fields: CaseID (Primary Key) StatusID (looked up in another table - Open, Pending, or Closed) Status Comment (memo field) Date&Time...
8
by: Yu SONG | last post by:
Hi all, What would be the most efficient way to save an array of floats to a file (in text format)? At the moment, my code looks like: /* * Saving an array of floats to a file
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
9
by: =?Utf-8?B?TWlrZTk5MDA=?= | last post by:
I save a number in the table and want to get that number again, but the number I get has lower precision than I expect. For example, when I divide 10/3 I get 3.3333333333333335 if the variable is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...

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.