Formating currency on label

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

    Formating currency on label

    Hi, I need to show on a label the data coming from db and it must show a
    currency... I'm using a SqlDataReader reader, but doesnt work...

    lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

    Can you help me ? Thanks!

    VS 2005 asp.net C# 2.0


  • George Ter-Saakov

    #2
    Re: Formating currency on label

    "Show currency" is kind of vague....as "does not work"....I bet it works
    just does not give you result you want :)

    After you did reader[1].ToString() it becomes string and you can not apply
    {0:c} to it. Since it only applicable to Decimal datatypes (numerics
    probably too).

    Not sure why you doing it that way

    lblPreco.Text = reader.GetDecim al(1).ToString( "c") should work...
    Plus it's much faster ....

    George.


    "Paulo" <eris_paulo@ter ra.com.brwrote in message
    news:eGdCNestIH A.2064@TK2MSFTN GP05.phx.gbl...
    Hi, I need to show on a label the data coming from db and it must show a
    currency... I'm using a SqlDataReader reader, but doesnt work...
    >
    lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");
    >
    Can you help me ? Thanks!
    >
    VS 2005 asp.net C# 2.0
    >

    Comment

    • Paulo

      #3
      Re: Formating currency on label

      George, I found something on google:

      lblPreco.Text = string.Format(" {0:c}", reader[1]);

      Thank you very much!

      "George Ter-Saakov" <gt-nsp@cardone.com escreveu na mensagem
      news:%23s6fLvst IHA.2208@TK2MSF TNGP04.phx.gbl. ..
      "Show currency" is kind of vague....as "does not work"....I bet it works
      just does not give you result you want :)
      >
      After you did reader[1].ToString() it becomes string and you can not apply
      {0:c} to it. Since it only applicable to Decimal datatypes (numerics
      probably too).
      >
      Not sure why you doing it that way
      >
      lblPreco.Text = reader.GetDecim al(1).ToString( "c") should work...
      Plus it's much faster ....
      >
      George.
      >
      >
      "Paulo" <eris_paulo@ter ra.com.brwrote in message
      news:eGdCNestIH A.2064@TK2MSFTN GP05.phx.gbl...
      >Hi, I need to show on a label the data coming from db and it must show a
      >currency... I'm using a SqlDataReader reader, but doesnt work...
      >>
      >lblPreco.Tex t = Eval(reader[1].ToString(), "{0:c}");
      >>
      >Can you help me ? Thanks!
      >>
      >VS 2005 asp.net C# 2.0
      >>
      >
      >

      Comment

      • sloan

        #4
        Re: Formating currency on label

        Agreed.

        You should always pick the granular "get".

        ..GetString()
        ..GetDateTime
        ..GetInt32()
        etc, etc.

        Instead of .GetValue() ... or how you're (mis) using the ToString().



        "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
        news:%23s6fLvst IHA.2208@TK2MSF TNGP04.phx.gbl. ..
        "Show currency" is kind of vague....as "does not work"....I bet it works
        just does not give you result you want :)
        >
        After you did reader[1].ToString() it becomes string and you can not apply
        {0:c} to it. Since it only applicable to Decimal datatypes (numerics
        probably too).
        >
        Not sure why you doing it that way
        >
        lblPreco.Text = reader.GetDecim al(1).ToString( "c") should work...
        Plus it's much faster ....
        >
        George.
        >
        >
        "Paulo" <eris_paulo@ter ra.com.brwrote in message
        news:eGdCNestIH A.2064@TK2MSFTN GP05.phx.gbl...
        >Hi, I need to show on a label the data coming from db and it must show a
        >currency... I'm using a SqlDataReader reader, but doesnt work...
        >>
        >lblPreco.Tex t = Eval(reader[1].ToString(), "{0:c}");
        >>
        >Can you help me ? Thanks!
        >>
        >VS 2005 asp.net C# 2.0
        >>
        >
        >

        Comment

        • George Ter-Saakov

          #5
          Re: Formating currency on label

          That is pretty much the same thing except slower :)

          reader[1] returns an object that is actually has type Decimal.
          Then you leave string.Format to figure it out and apply {0:c} accordingly.

          with reader.GetDecim al(1).ToString( "c") the guessing of which type reader[1]
          is already done by you. Since GetDecimal returns Decimal.

          George.


          "Paulo" <eris_paulo@ter ra.com.brwrote in message
          news:OKiqRxstIH A.1220@TK2MSFTN GP04.phx.gbl...
          George, I found something on google:
          >
          lblPreco.Text = string.Format(" {0:c}", reader[1]);
          >
          Thank you very much!
          >
          "George Ter-Saakov" <gt-nsp@cardone.com escreveu na mensagem
          news:%23s6fLvst IHA.2208@TK2MSF TNGP04.phx.gbl. ..
          >"Show currency" is kind of vague....as "does not work"....I bet it works
          >just does not give you result you want :)
          >>
          >After you did reader[1].ToString() it becomes string and you can not
          >apply {0:c} to it. Since it only applicable to Decimal datatypes
          >(numerics probably too).
          >>
          >Not sure why you doing it that way
          >>
          >lblPreco.Tex t = reader.GetDecim al(1).ToString( "c") should work...
          >Plus it's much faster ....
          >>
          >George.
          >>
          >>
          >"Paulo" <eris_paulo@ter ra.com.brwrote in message
          >news:eGdCNestI HA.2064@TK2MSFT NGP05.phx.gbl.. .
          >>Hi, I need to show on a label the data coming from db and it must show a
          >>currency... I'm using a SqlDataReader reader, but doesnt work...
          >>>
          >>lblPreco.Te xt = Eval(reader[1].ToString(), "{0:c}");
          >>>
          >>Can you help me ? Thanks!
          >>>
          >>VS 2005 asp.net C# 2.0
          >>>
          >>
          >>
          >
          >

          Comment

          Working...