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

How to retain a decimal?

Hello.

If a convert a string (string number = "24.45") into a double, using the
Convert class ((double doublenumber = Convert.ToDouble(number)), the result
will have the value 2445.

How do I retain the correct value?
Nov 19 '05 #1
6 1380
..net offers the decimal type. use it instead of a double

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET
-------------------------------------------------------------------------------
"the friendly display name"
<th********************@discussions.microsoft.co m> wrote in message
news:9D**********************************@microsof t.com...
Hello.

If a convert a string (string number = "24.45") into a double, using the
Convert class ((double doublenumber = Convert.ToDouble(number)), the
result
will have the value 2445.

How do I retain the correct value?

Nov 19 '05 #2
That doesn't help one bit.

decimal decimalnumber = Convert.ToDecimal("25.34");

decimalnumber will have the value 2534 after this. I have tried it already.
This problem that I receive should be quite common.

As example, you have a textbox on a webform, and you need to enter a price
for a product. If you convert the text of the textbox, the problem should
clear:

User entered the value 25.55 into the textbox.
double number = Convert.ToDouble(textbox.text);

number has the value 2555. How to retain the value 25.55 ?
"Alvin Bruney [MVP - ASP.NET]" wrote:
..net offers the decimal type. use it instead of a double

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET


Nov 19 '05 #3
> This problem that I receive should be quite common.

No, it is not that common, 1st time I've seen this.
put a breakpoint in your code and examine the values, I think you are
passing in "2534".
"the friendly display name"
<th********************@discussions.microsoft.co m> wrote in message
news:86**********************************@microsof t.com...
That doesn't help one bit.

decimal decimalnumber = Convert.ToDecimal("25.34");

decimalnumber will have the value 2534 after this. I have tried it
already.
This problem that I receive should be quite common.

As example, you have a textbox on a webform, and you need to enter a price
for a product. If you convert the text of the textbox, the problem should
clear:

User entered the value 25.55 into the textbox.
double number = Convert.ToDouble(textbox.text);

number has the value 2555. How to retain the value 25.55 ?
"Alvin Bruney [MVP - ASP.NET]" wrote:
..net offers the decimal type. use it instead of a double

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET

Nov 19 '05 #4
decimal decimalnumber = Convert.ToDecimal("25.34");
provides a value of "25.34".
decimalnumber will have the value 2534 after this. I have tried it
already. Nope, you could not have possibly tried it!

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET
-------------------------------------------------------------------------------
"the friendly display name"
<th********************@discussions.microsoft.co m> wrote in message
news:86**********************************@microsof t.com... That doesn't help one bit.

decimal decimalnumber = Convert.ToDecimal("25.34");

decimalnumber will have the value 2534 after this. I have tried it
already.
This problem that I receive should be quite common.

As example, you have a textbox on a webform, and you need to enter a price
for a product. If you convert the text of the textbox, the problem should
clear:

User entered the value 25.55 into the textbox.
double number = Convert.ToDouble(textbox.text);

number has the value 2555. How to retain the value 25.55 ?
"Alvin Bruney [MVP - ASP.NET]" wrote:
..net offers the decimal type. use it instead of a double

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET

Nov 19 '05 #5
That's very odd.

When I try it, decimalnumber returns 25.34


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"the friendly display name" <th********************@discussions.microsoft.co m> wrote in
message news:86**********************************@microsof t.com...
That doesn't help one bit.

decimal decimalnumber = Convert.ToDecimal("25.34");

decimalnumber will have the value 2534 after this. I have tried it already.
This problem that I receive should be quite common.

As example, you have a textbox on a webform, and you need to enter a price
for a product. If you convert the text of the textbox, the problem should
clear:

User entered the value 25.55 into the textbox.
double number = Convert.ToDouble(textbox.text);

number has the value 2555. How to retain the value 25.55 ?
"Alvin Bruney [MVP - ASP.NET]" wrote:
..net offers the decimal type. use it instead of a double

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
Forth-coming VSTO.NET

Nov 19 '05 #6
the friendly display name wrote:
That doesn't help one bit.

decimal decimalnumber = Convert.ToDecimal("25.34");

decimalnumber will have the value 2534 after this. I have tried it already.
This problem that I receive should be quite common.

As example, you have a textbox on a webform, and you need to enter a price
for a product. If you convert the text of the textbox, the problem should
clear:

User entered the value 25.55 into the textbox.
double number = Convert.ToDouble(textbox.text);

number has the value 2555. How to retain the value 25.55 ?

Sounds like some kind of locale/I18N problem. What happens if you try
to convert "25,55" to decimal?

Damien

Nov 19 '05 #7

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
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....
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
1
by: KC | last post by:
Hi, I created a new event log source and log and user WriteEntry to enter the log as follows: ' Create the source, if it does not already exist. If Not EventLog.SourceExists("MySource") Then...
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
3
by: raaman rai | last post by:
Hi Fellas, i need to understand how to retain the submtted form values during an Edit/Update operation. When i add the information from a form, i retain the form values in the following way incase...
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...
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: 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
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,...
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...
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...

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.