0

i am trying to get percentage of values using textboxes. for me my code is working good. after getting percentage, i am storing this in a gridview and then i am using mouseclick event and on clicking gridview row i got that data back to textboxes.

the problem stars now when i change a value in textbox. it show me the percentage in other textbox, but it add 2 more zeros i.e. 4 zeros after decimal. i want to avoid this i need only 2 zero.

string t4 = textBox4.Text;
long it4 = Int64.Parse(t4);
string t5 = textBox5.Text;
var it5 = decimal.Parse(t5); 
//decimal.Parse(t5);
decimal a;
a = it4 * it5;
string t8 = textBox8.Text;
var it8 = decimal.Parse(t8);
decimal b;
b = ((a * it8) / 100);
textBox9.Text = b.ToString();
James Z
  • 12,209
  • 10
  • 24
  • 44
Pravee
  • 9
  • 4
  • What language? Please tag the language you are using. "decimal" is awfully broad. – lurker Apr 08 '18 at 14:47
  • using c# and Database as sql – Pravee Apr 08 '18 at 14:49
  • `b.ToString ("#.##");` will give you 2 decimal places. Search for *C# decimal type format* for more details. Also see [this question](https://stackoverflow.com/questions/164926/how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-page). – CodingYoshi Apr 08 '18 at 15:01
  • It's not clear where the database part comes in - but please could you provide a [mcve], including what you want to happen vs what actually happens? A console app with hardcoded input would be fine - potentially not even strings, but the hardcoded values of the results of parsing. – Jon Skeet Apr 08 '18 at 15:02
  • i got my Solution thanks @lurker actulay i was using decimal but now i am using double and now its working – Pravee Apr 08 '18 at 15:11
  • Possible duplicate of [How do I round a decimal value to 2 decimal places (for output on a page)](https://stackoverflow.com/questions/164926/how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-page) – ElasticCode Apr 08 '18 at 16:43

0 Answers0