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 6: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 Sergey Alexandrovich Kryukov 566
1 OriginalGriff 331
2 Maciej Los 170
3 Mehdi Gholam 145
4 PIEBALDconsult 140
0 Sergey Alexandrovich Kryukov 11,384
1 OriginalGriff 5,783
2 Maciej Los 5,684
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.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