Formatting Money

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

    Formatting Money

    If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Formatting Money

    Ian,

    If I understand this correctly, the value is basically the number of
    cents, correct?

    If that is the case, I would do this (I would say to use a decimal since
    you are dealing with money):

    Decimal amount = (Decimal) longAmount / 100;

    And then call ToString, passing "$####.##", and it should work.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Ian Semmel" <isemmelNOJUNK@ NOKUNKrocketcom p.com.auwrote in message
    news:OA%23QBXf4 IHA.4260@TK2MSF TNGP06.phx.gbl. ..
    If I have an Int64 which is $$$$$cc, what is the best way to format it to
    a string '$nnnn.cc' ?

    Comment

    • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

      #3
      RE: Formatting Money

      You need to call something like this:

      Int64 myNum = 123456L; //$1234.56
      String myString= String.Format(" C",myNum/100);

      Is that was you mean? The C means format it as a currency. Hear is a good
      cheat sheet for formatting strings:


      --
      Ciaran O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }



      "Ian Semmel" wrote:
      If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
      >

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: Formatting Money

        Ian Semmel wrote:
        If I have an Int64 which is $$$$$cc, what is the best way to format it
        to a string '$nnnn.cc' ?
        Try study:


        Arne

        Comment

        • Ian Semmel

          #5
          Re: Formatting Money

          Thanks for your replies, I have a greater insight into formatting now.

          I had come to the conclusion that I had to convert the number to decimal (or float) for the formatting to work.

          Perhaps I was looking for something akin to the old cobol 'implied decimal point' which could be applied to binary fields to tell
          the compiler where to put the '.' in formatted output.

          Ian Semmel wrote:
          If I have an Int64 which is $$$$$cc, what is the best way to format it
          to a string '$nnnn.cc' ?

          Comment

          Working...