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

Truncating decimal points

can some one pls suggest me why?

StreamWriter sw = new StreamWriter(@"c:\Temp\1.txt");
double dd1;
double dd2;
double dd3;
double dd4;
dd1 = 1452.123456789876123456;
dd2 = 1452.123456789123123456;
dd3 = 1452.123456789567123456;
dd4 = 1452.123456789456123456;

sw.WriteLine(dd1.ToString());
sw.WriteLine(dd2.ToString("G"));
sw.WriteLine(dd3);
sw.WriteLine(dd4);
sw.Close();
Output
----------
1452.12345678988
1452.12345678912
1452.12345678957
1452.12345678946
why it round off the values to 11 decimal places?

Thanks
Prakash

Jun 20 '07 #1
2 2053
See http://msdn2.microsoft.com/en-us/lib...94(VS.80).aspx

For the [G]eneral format, up to 15 digits are returned; you can ask
for 17... double simply can't guarantee 22... have a closer look at
what is stored... you will probably find that dd1-4 have wandered
somewhat from the numbers you specified.

Marc
Jun 20 '07 #2
On Jun 20, 1:55 pm, prakashdeh...@gmail.com wrote:
can some one pls suggest me why?
<snip>
why it round off the values to 11 decimal places?
See http://pobox.com/~skeet/csharp/floatingpoint.html

Jon

Jun 20 '07 #3

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

Similar topics

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....
5
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any...
5
by: GaryB | last post by:
I have a database field that is the product of a multiply in a sql statement and it sometimes has 5 or more decimal places. I want to truncate beyond the 2nd decimal place(###.##). I figured a...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
3
by: cj | last post by:
I want 7 * .105263 to result in an int32 value of 0. and 7 * .189021 to result in an int32 value of 1. I don't want to round. How can I just drop the decimal places?
1
by: ianhen | last post by:
Hi I have a Web Form which I need to get results shown to 2 decimal points only. In the Head I have: - function heatoutput() { var vWidth=document.heatcalculator.roomwidth.value; var...
2
by: Bre035 | last post by:
I have created a Make-table query in Microsoft Access 2003 to retrieve comments for designated records. The queries runs fine, but it doesn't pull all the text from the comments column of the DB2...
4
by: Todd | last post by:
I have a function that takes a double and truncates it to a specified number of decimal places. I've found that I have to add a small number to the input value otherwise I get errors due to the...
1
by: Serenityquinn15 | last post by:
Hi! I have a little trouble about in truncating numbers. What i want to do is to get the two decimal places. here's the example: when i try to get the half of 20500.39 it shows like...
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
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: 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: 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
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...

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.