Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i multiply two number means i need to get in decimal
Ex: 10*5=50.00 how it is?
Posted
Updated 22-Sep-11 23:36pm
v2
Comments
André Kraak 23-Sep-11 5:33am    
Your question is to vague, please try rephrasing it and/or be more specific.
vasanthkarthi 23-Sep-11 5:36am    
am asking decimal value 00 coming how it is,,,

I assume you want to display the value with two decimals. You can do that using format string.
E.g.
C#
Console.Write("{0:#.00}", 50);

see String Formatting in C#[^]
 
Share this answer
 
Comments
Mehdi Gholam 23-Sep-11 5:39am    
My 5!
Simon Bang Terkildsen 23-Sep-11 5:48am    
Thank you, Mehdi
This is just a matter of number representation, for instance:
C#
int k = 10 * 5;
Console.WriteLine("Number with two decimals: {0}", k.ToString("F2"));

could do the trick.
 
Share this answer
 
Comments
Simon Bang Terkildsen 23-Sep-11 5:48am    
Wouldn't it be better to include the formating in the format string and avoid ToString?
Console.WriteLine("Number with two decimals: {0:F2}", k);
it just seems more clean to me, especially if you pass more than one arguments to the format string.
vasanthkarthi 23-Sep-11 5:56am    
F2 means
Try
C#
int a=1; int b=2;
decimal x = a * b;
 
Share this answer
 
C#
int a = 9;
int b = 5;
decimal c = checked((decimal)a / b);
// X.XX Format

Console.WriteLine("{0:F2}", c);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900