Format double doesn't work

Discussion in 'ASP .Net' started by staeri@gmail.com, Aug 2, 2006.

  1. Guest

    If trying to format a value in a GridView with the following function
    to be shown with thousand separators. If no value exists it should show
    0.

    If I send the value = 45000 it is still shown as 45000, not 45.000.
    Why?


    Function FormatAmount(ByVal value As Object) As String
    'Show with thousand separator if not is null, else show 0
    Dim strShow As String

    If value Is DBNull.Value Then
    strShow = "0"
    Else
    Dim dblAmount As Double = Convert.ToDouble(value)
    strShow = Format("{0:#,##0}", dblAmount)
    End If

    Return strShow
    End Function

    Can someone please help me?

    Regards,

    S
     
    , Aug 2, 2006
    #1
    1. Advertising

  2. Use, strShow = String.Format("{0:#,##0}", dblAmount)

    instead of, strShow = Format("{0:#,##0}", dblAmount)

    if String.Format is not specified, Format function within Strings class is
    used.


    - Augustin



    "" wrote:

    > If trying to format a value in a GridView with the following function
    > to be shown with thousand separators. If no value exists it should show
    > 0.
    >
    > If I send the value = 45000 it is still shown as 45000, not 45.000.
    > Why?
    >
    >
    > Function FormatAmount(ByVal value As Object) As String
    > 'Show with thousand separator if not is null, else show 0
    > Dim strShow As String
    >
    > If value Is DBNull.Value Then
    > strShow = "0"
    > Else
    > Dim dblAmount As Double = Convert.ToDouble(value)
    > strShow = Format("{0:#,##0}", dblAmount)
    > End If
    >
    > Return strShow
    > End Function
    >
    > Can someone please help me?
    >
    > Regards,
    >
    > S
    >
    >
     
    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmE=?=, Aug 2, 2006
    #2
    1. Advertising

  3. Winista Guest

    This should help..

    http://www.netomatix.com/development/GridViewDataFormatting.aspx

    Try setting HtmlEncode="False" for your column.

    <> wrote in message
    news:...
    > If trying to format a value in a GridView with the following function
    > to be shown with thousand separators. If no value exists it should show
    > 0.
    >
    > If I send the value = 45000 it is still shown as 45000, not 45.000.
    > Why?
    >
    >
    > Function FormatAmount(ByVal value As Object) As String
    > 'Show with thousand separator if not is null, else show 0
    > Dim strShow As String
    >
    > If value Is DBNull.Value Then
    > strShow = "0"
    > Else
    > Dim dblAmount As Double = Convert.ToDouble(value)
    > strShow = Format("{0:#,##0}", dblAmount)
    > End If
    >
    > Return strShow
    > End Function
    >
    > Can someone please help me?
    >
    > Regards,
    >
    > S
    >
     
    Winista, Aug 2, 2006
    #3
  4. Try the .ToString() with formatting params, maybe without the 0: part.



    <> schreef in bericht
    news:...
    > If trying to format a value in a GridView with the following function
    > to be shown with thousand separators. If no value exists it should show
    > 0.
    >
    > If I send the value = 45000 it is still shown as 45000, not 45.000.
    > Why?
    >
    >
    > Function FormatAmount(ByVal value As Object) As String
    > 'Show with thousand separator if not is null, else show 0
    > Dim strShow As String
    >
    > If value Is DBNull.Value Then
    > strShow = "0"
    > Else
    > Dim dblAmount As Double = Convert.ToDouble(value)
    > strShow = Format("{0:#,##0}", dblAmount)
    > End If
    >
    > Return strShow
    > End Function
    >
    > Can someone please help me?
    >
    > Regards,
    >
    > S
    >
     
    Edwin Knoppert, Aug 2, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,510
    Victor Bazarov
    Feb 17, 2005
  2. D. Patrick

    format number #,### doesn't work right

    D. Patrick, Jun 14, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    14,589
    shogo2040
    Mar 22, 2011
  3. MZ
    Replies:
    7
    Views:
    832
    Ed Mullen
    Mar 17, 2008
  4. Disc Magnet
    Replies:
    3
    Views:
    737
    David Thompson
    Mar 24, 2010
  5. Tilman
    Replies:
    0
    Views:
    418
    Tilman
    Mar 19, 2008
Loading...

Share This Page