dcsimg
Results 1 to 10 of 10

Thread: Displaying Currency on a Web Page

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Question Displaying Currency on a Web Page

    I have an Access Database that contains a field "Price" formatted as follows:

    DataType: Number
    Field Size: Decimal
    Format: Currency
    Precision: 18
    Scale: 0
    Decimal Places: 2

    I have entered a value, e.g., 59, into the database record. When I look at the field in the Database it appears as $59.00.

    On my web page I have the following code:

    <% Response.Write(rs.Fields("Price").value)%>

    All that is output is 59

    What do I have to change/do to get the output to be $59.00?

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Re: Displaying Currency on a Web Page

    My Bad - The scale should be 2 vs. 0.

  3. #3
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Displaying Currency on a Web Page

    On the website, try using the String.Format method for currency. It should put it in $00.00 format for you. The follow article describes using format strings: http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Re: Displaying Currency on a Web Page

    I followed the example in the article and these are the results:

    The Dim Cost As Double generated an error.

    So them I tried this:

    Dim Cost
    Cost = rs.Fields("Price").value
    Console.WriteLine(Cost.ToString("C", CultureInfo.CurrentCulture))

    The third statement generated an Object Required error.

  5. #5
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Displaying Currency on a Web Page

    Try this:

    Console.WriteLine(String.Format("{0,0:C}", Cost))
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,446

    Re: Displaying Currency on a Web Page

    ASP? or ASP.NET? If using ASP, then the above suggestion will work... if using ASP.NET, then is should work... I suspect though, given the location of this post, and the code given, that it's ASP ... which means this might work:

    <% Response.Write(format(rs.Fields("Price").value), "$0.00")%>

    I think I have the parameters right... they may need to be swapped...

    the reason the third line failed is because you tried to write to the Console, only in a web page, that doesn't exist...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Re: Displaying Currency on a Web Page

    Received error:

    Wrong number of arguments or invalid property assignment: 'String'

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Re: Displaying Currency on a Web Page

    Tried your suggestion. Another error message:

    Microsoft VBScript compilation error '800a0414'

    Cannot use parentheses when calling a Sub

    /featured.asp, line 158

    Response.Write(format(rs.Fields("Price").value), "$0.00")
    -------------------------------------------------------------^


    I'm beginning to think this is impossible trying to get database values to appear in HTML in the correct format.

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    12

    Resolved Re: Displaying Currency on a Web Page

    Hi Matt,

    Thanks for the hint about using the Format statement. I searched this time for formatting data in ASP and found this reference:

    http://www.virtualsplat.com/tips/asp...t-currency.asp

    I tried this statement:

    Response.Write(FormatCurrency(rs.Fields("Price").value))

    and it worked!

    Problem solved.

  10. #10
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Displaying Currency on a Web Page

    Quote Originally Posted by larry369 View Post
    Hi Matt,

    Thanks for the hint about using the Format statement. I searched this time for formatting data in ASP and found this reference:

    http://www.virtualsplat.com/tips/asp...t-currency.asp

    I tried this statement:

    Response.Write(FormatCurrency(rs.Fields("Price").value))

    and it worked!

    Problem solved.
    Good deal - glad it worked. Make sure to mark the thread resolved and rate the post if you think I deserved it.

    PS - Welcome to the forums
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width