Link to home
Create AccountLog in
Avatar of cdemott33
cdemott33Flag for United States of America

asked on

How to fomat a double in a textbox

I have currency values that are stored in my database as a double.  I need to load these values into a textbox so they can be changed, but I want to round them up to 2 decimal places.  How do I do this?

For example:  Database value for ActualCost is 1436.9051
I want to round this up and display it in a textbox as 1436.91

I can't use the {0:c} because it adds the dollar sign.  

Is there another format I can use to get this to work?

' This doesn't work becuase it add the $

m_tbActualCost.Text = String.Format("{0:c}", dt.Rows(0).Item("ActualCost"))

' What format can I use that will work?

Open in new window

Avatar of soloworm
soloworm
Flag of United States of America image

For what i understood about your decimal place problem i think tis will resolve.
 
<%
'Example:
 Original_double = 12345.6789
'Y_Variable is your variable with the double
'You will declare one other variable that will be equal
' to Round (y_variable,and the number of decimal places) 
 Final_double = Round(Original_double,2)
 Response.Write(Final_double)
%>

Open in new window

Avatar of Rick
Rick

m_tbActualCost.Text = Format(math.round(cdbl(dt.Rows(0).Item("ActualCost")), 2), "##,##0.00")
ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
try this,

           decimal text;
            text = 1.989m;
            Label1.Text = String.Format("{0:#.##}", text);
Avatar of cdemott33

ASKER

This pointed me in the right direction, but I had to use {0:F2} to get it to work correctly