Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have values as 2313 ,546.689,2314.9.

I have rounded off these double values but the result as displaying as

2313,546.7,2314.9.

but I want result as

2313.0,546.7,2314.9.

means if the no is 2313 then it should be display as 2313.0 without changing it .ToString(0.0) coz I have to use it for filtering.

Thanks
Mohd Wasif
Posted

try this.
hope it will helpful for you.
C#
int val = 28;
      string formatted = val.ToString("N1");
 
Share this answer
 
Comments
Abhinav S 11-Sep-12 2:22am    
5!
Hi,

you can go for CultureInfo Number formats.

check this
Double.ToString Method (IFormatProvider)[^]
Custom Numeric Format Strings[^]
Formatting Types[^]

For more information refer this[^]

hope it helps.
 
Share this answer
 
Comments
Abhinav S 11-Sep-12 2:21am    
5!
Karthik Harve 11-Sep-12 2:23am    
Thank you.
C#
string a = (2313).ToString("0.0"); // result a=2313.0

Happy Coding!
:)
 
Share this answer
 
v2
I have taken One textBox to enter integer and on Click of OK Button , it displays Dicimal value .

Following is Code

ASP.NET
<table>
   <tr align="left">
    <td align="left">
     <asp:textbox id="txtNumber" runat="server" xmlns:asp="#unknown"></asp:textbox>
     </td>
     <td align="left">
     <asp:button id="btnOK" runat="server" text="OK" xmlns:asp="#unknown" />
     </td>
   </tr>
   <tr align="left">
   <td align="left">
   <asp:label id="lblDisplay" runat="server" text="" xmlns:asp="#unknown"></asp:label>
   </td>
   </tr>
   </table>



Code to Convert in Code Behind

VB
Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
       Dim intNum As Integer
       intNum = txtNumber.Text
       lblDisplay.Text = Decimal.Round(intNum, 2).ToString("f1")
   End Sub
 
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