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 OriginalGriff 339
1 DineshMaind 95
2 Sergey Alexandrovich Kryukov 94
3 majid torfi 85
4 kbrandwijk 75
0 Zubair MCA 55
1 OriginalGriff 55
2 sankarsan parida 55
3 harshavardhan12345678 45
4 Sandeep Londhe 45


Advertise | Privacy | Mobile
Web01 | 2.8.140827.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