Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am having value for 12.5 i want output like this format 12.0 and 16.6 this value i need output 17.0 plz help me sir
Posted
Updated 24-Apr-14 5:04am
v2
Comments
[no name] 24-Apr-14 5:43am    
refer
http://www.dotnetperls.com/math-round
King Fisher 25-Apr-14 8:53am    
have you solved this?

Try this:
C#
double before1 = 12.5;
double after1 = Math.Round(before1);
Console.WriteLine(after1.ToString("F1", CultureInfo.CurrentCulture));

decimal before2 = 12.5M;
decimal after2 = Math.Round(before2);
Console.WriteLine(after2.ToString("F1", CultureInfo.CurrentCulture));

Read more: Standard Numeric Format Strings[^]
 
Share this answer
 
Try this
C#
double outputValue = 0;

outputValue = Math.Round(your_decimal_value, 0);
Console.WriteLine(string.Format("{0:#0.0}", outputValue));
 
Share this answer
 
Simply Math.Round method will serve your purpose.
 
Share this answer
 
v2
have you googled it.
There is a method for you

Math.Round in c#
 
Share this answer
 
Comments
satheeshkumar chinnadurai 25-Apr-14 8:35am    
SELECT Shift, Date,
(CASE WHEN Shift=1 THEN 'Morning' WHEN Shift=2 THEN 'Evening'END) AS ShiftName,
SUM(ISNULL(Liter,0))
AS TotalLiters,SUM(CAN) as CAN
FROM dbo.Purchase
WHERE Date='2014-05-22' AND Shift = 1
GROUP BY Liter, Date, Shift
UNION


SELECT Shift, Date,
(CASE WHEN Shift=1 THEN 'Morning' WHEN Shift=2 THEN 'Evening'END) AS ShiftName,
SUM(ISNULL(Liter,0))
AS TotalLiters ,SUM(CAN) as CAN
FROM dbo.Purchase
WHERE Date= dateadd(day,datediff(day,1,'2014-05-22'),0) AND Shift = 2
GROUP BY Liter, Date, Shift
King Fisher 25-Apr-14 8:51am    
what's this?
satheeshkumar chinnadurai 30-Apr-14 5:35am    
MessageBox.Show(dateTimePicker1.Value.ToString("yyyy-MM-dd"));
satheeshkumar chinnadurai 30-Apr-14 7:21am    
http://findicons.com/search/cow
King Fisher 30-Apr-14 7:45am    
what is this?

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