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

Decimal d1 = Decimal.Parse("0.1"); // = 1?!?

Im hoping someone can help me to work out where/what Im missing here.
Ive a line in a moderately sized program

decimal d1 = Decimal.Parse("0.1");

When I check the result in Visual Studio or perform any math using d1,
the value of d1 is 1.

Thinking I was missing something obvious (it is late here), I changed
d1 the line to

Decimal decVariable = Decimal.Parse("0.8");

And the result was 8.

Things became even more bizarre when I changed the Decimal to a Double
with the same result and then wrote a seperate little test app and got
the results I expected.

Is there anything obvious I am missing here? Its been a while since I
worked with c#/.net (this is VS 2005/.Net 2.0) and am sure its
something Im doing wrong...

Tia

May 27 '06 #1
4 10047
10 minutes away from the PC and I worked it out - the app is localised
and Id switched to a German locale!

That said - now Im wondering how to deal with settings like this when
they are user configurable via app.config.........

May 27 '06 #2
You should use the overload that lets you specify IFormatProvider used for
parsing the strings

decimal d = decimal.Parse("2.3",
System.Globalization.CultureInfo.InvariantCulture. NumberFormat);

<le**@citymutual.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
10 minutes away from the PC and I worked it out - the app is localised
and Id switched to a German locale!

That said - now Im wondering how to deal with settings like this when
they are user configurable via app.config.........

May 27 '06 #3
<le**@citymutual.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Im hoping someone can help me to work out where/what Im missing here.
Ive a line in a moderately sized program

decimal d1 = Decimal.Parse("0.1");

When I check the result in Visual Studio or perform any math using d1,
the value of d1 is 1.

Thinking I was missing something obvious (it is late here), I changed
d1 the line to

Decimal decVariable = Decimal.Parse("0.8");

And the result was 8.

Things became even more bizarre when I changed the Decimal to a Double
with the same result and then wrote a seperate little test app and got
the results I expected.

Is there anything obvious I am missing here? Its been a while since I
worked with c#/.net (this is VS 2005/.Net 2.0) and am sure its
something Im doing wrong...

Hi Tia,

I'm using VS2005 too. I copy and pasted your code and it is working fine
for me. Did you try copying it out of your current project and pasting it
into a new project to see the results. Maybe try debugging by commenting
out all the algorithm except for that line, run the code to validate
results, and continue uncommenting and running again until you find where
the problem is.

Joe
--
http://www.csharp-station.com
May 27 '06 #4
<le**@citymutual.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
10 minutes away from the PC and I worked it out - the app is localised
and Id switched to a German locale!

That said - now Im wondering how to deal with settings like this when
they are user configurable via app.config.........


Makes perfect sense to me now. Please ignore my previous post. Lebesgue
got it right.

Joe
--
http://www.csharp-station.com
May 27 '06 #5

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

Similar topics

13
by: - Steve - | last post by:
I've been given a school assignment and while everything else is easy there's one topic I'm completley lost on. I've been given an ASCII file that looks like this. During start-up, the program...
4
by: Ed Sutton | last post by:
Is there an easy conversion from a hex string, for example "0x1234" to an int? I have written my own many times in other languages, I was just wondering if there might be something already...
5
by: Dan C Douglas | last post by:
I have just installed VS.NET 2003 on my computer. I have a project that I have been developing on VS.NET 2002. I haven't upgraded this project to VS.NET 2003 yet and I am still developing it in...
9
by: rocio | last post by:
How can I format a string like this: 12924.999999999999 to print 12,925 ?
1
by: Steven Spits | last post by:
Hi, Suppose decimal Price contains 12,3. Price.ToString("C2") gives 12,30 ? (yes, I'm located in Europe). What would be the best way to convert this string to a decimal again? Steven - -...
18
by: Martin Jørgensen | last post by:
Hi, Today I got a really strange problem... I've made myself a data-file and I read in data from that file.... When I read something like this line: 03 04 05, 00 04 01, 05 03 07, 08 03...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
10
by: mcbobin | last post by:
Hi, Here's hoping someone can help... I'm using a stored procedure to return a single row of data ie a DataRow e.g. public static DataRow GetManualDailySplits(string prmLocationID, string
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
3
by: roger.dunham | last post by:
Hi there, I am writing an application that performs calculations on records within a data table. There may be many records in a data table. There are situations where the calculation may not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.