Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Double total = Convert.ToDouble(dt.Rows[0]["Amount_with_markup"]);
                   Double paid = Convert.ToDouble(txtpaid.Text);
                   Double rem =Math.Round(total - paid);
                   txtremaining.Text = rem.ToString(".####");
Posted 14-Jan-13 7:06am
Comments
Sergey Alexandrovich Kryukov at 14-Jan-13 15:43pm
   
I don't think you really need Round.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
.#### is max. 4 decimal places. Try .0000 instead:
txtremaining.Text = rem.ToString(".0000");
Hope this helps.
  Permalink  
Comments
ridoy at 14-Jan-13 12:40pm
   
+5
ProgramFOX at 14-Jan-13 12:41pm
   
Thank you!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can also handle only showing 4 decimal places in your Math.Round.
 
Double total = Convert.ToDouble(20.04353450);
Double paid = Convert.ToDouble(19.25641654);
Double rem = Math.Round(total - paid, 4, MidpointRounding.AwayFromZero);
txtremaining.Text = rem.ToString();
  Permalink  
Comments
ridoy at 14-Jan-13 12:40pm
   
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 315
1 Zoltán Zörgő 170
2 OriginalGriff 150
3 Sergey Alexandrovich Kryukov 120
4 Maciej Los 115
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100