Convert Formatted Double Into String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Hart

    Convert Formatted Double Into String

    I have a double stored in a DataTable: dt.Rows(i)(Merg eFieldName)



    I want to format this and store it into a string.



    I have formatting stored in a database, such as "$#,##0.00"



    How do I use this formatting, apply it to dt.Rows(i)(Merg eFieldName), which
    is a double, and then store it in a string?



    So if the value of dt.Rows(i)(Merg eFieldName) is 14,122.05. I would get
    $14,122.05.



    Derek


  • Armin Zingler

    #2
    Re: Convert Formatted Double Into String

    "Derek Hart" <derekmhart@yah oo.comschrieb
    I have a double stored in a DataTable: dt.Rows(i)(Merg eFieldName)
    >
    >
    >
    I want to format this and store it into a string.
    >
    >
    >
    I have formatting stored in a database, such as "$#,##0.00"
    >
    >
    >
    How do I use this formatting, apply it to
    dt.Rows(i)(Merg eFieldName), which is a double, and then store it in
    a string?
    >
    >
    >
    So if the value of dt.Rows(i)(Merg eFieldName) is 14,122.05. I would
    get $14,122.05.

    What's the format of the format? :) I guess it's one of these:
    Microsoft technical documentation for older versions of products, services and technologies.


    Example:
    dim fmt as string = "$#,##0.00"
    dim s as string

    s = directcast(dt.R ows(i)(MergeFie ldName), double).ToStrin g(fmt)


    Armin

    Comment

    • =?Utf-8?B?SmVmZiBXaW5u?=

      #3
      Re: Convert Formatted Double Into String

      As long as the type you're trying to format is a numeric data type the
      formatting will work just fine. However, if you're trying to take a string
      type that contains numeric data you will need to parse it to the appropriate
      type before you can format it.

      Example A:
      Dim s As String = "1234.44"
      s.ToString("$#, ##0.00")

      Will not work.

      Example B:
      Dim d As Double = Double.Parse("1 234.44")
      d.ToString("$#, ##0.00")

      Will work properly.

      "Armin Zingler" wrote:
      "Derek Hart" <derekmhart@yah oo.comschrieb
      I have a double stored in a DataTable: dt.Rows(i)(Merg eFieldName)



      I want to format this and store it into a string.



      I have formatting stored in a database, such as "$#,##0.00"



      How do I use this formatting, apply it to
      dt.Rows(i)(Merg eFieldName), which is a double, and then store it in
      a string?



      So if the value of dt.Rows(i)(Merg eFieldName) is 14,122.05. I would
      get $14,122.05.
      >
      >
      What's the format of the format? :) I guess it's one of these:
      Microsoft technical documentation for older versions of products, services and technologies.

      >
      Example:
      dim fmt as string = "$#,##0.00"
      dim s as string
      >
      s = directcast(dt.R ows(i)(MergeFie ldName), double).ToStrin g(fmt)
      >
      >
      Armin
      >
      >

      Comment

      Working...