Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Doubles as 0.00

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Ok, I'm fried, the closest starbucks is 5 minutes away driving, and I'm out of chocolate covered coffee beans: forgive me if this is a really easy question, my brain is functioning too well today.
;)

I need my double values to display as currency. But, in my code if the value is 0 it defaults to 0.0, not 0.00. And if the value it gets assigned is, say, 3.40, it gets rid of the last 0. Any quick, easy, non-code-intensive way around this?

Thanks guys...lunch in 1 1/2 hours...must get...more...coffee....

Jack
 
There is two ways to do this Jack. This first one is to put those format thingys into the page *not the code behind.
if it's a databinder call use this
<%# DataBinder.Eval(Container, &quot;DataItem.Rate&quot;, &quot;{0:C}&quot;) %>
if it's a plain feild then this should work
DataFormatString=&quot;{0:D}&quot;

The second, a little bit more code intensive is to do an if statment on them.

Dim money As Double
Dim temp, temp1 As String
money = 1.2

temp = money.ToString

temp1 = temp.Substring(temp.IndexOf(&quot;.&quot;))
If temp1.Length < 2 Then
temp = temp & 0
ElseIf temp1.Length > 2 Then
temp.Substring(0, (temp.Length - (temp1.Length - 2)))
End If

'temp is now the proper number
That'l do donkey, that'l do
[bravo] Mark
 
Did you try this:
Price=FormatNumber(Request(&quot;Price&quot;),2)
 
sonofa...
nice job ASPVB! You learn something everyday don't ya ;) That'l do donkey, that'l do
[bravo] Mark
 
formatCurrency() will go ahead and put the $ on there for ya if that's what you need, too.

If I'm not mistaken, I think it even puts parens around it if it's negative, which is a nice touch for reporting.
penny1.gif
penny1.gif
 
Kick @$$, thanks for all the ideas guys
:)

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top