Results 1 to 3 of 3

Thread: [RESOLVED] Always display 2 digits after decimal point

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Resolved [RESOLVED] Always display 2 digits after decimal point

    Hi there,

    whats the handiest way to always display 2 digits after a decimal point. Im using a double and i will convert it to String before displaying but i need it to show the 2 decimal places as the example below


    Eg
    5 -> 5.00
    5.0 ->5.00
    5.50->5.50
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Always display 2 digits after decimal point

    VB Code:
    1. Dim DoubleVar as Double=5D
    2. MsgBox(DoubleVar.ToString("N2"))

    http://msdn.microsoft.com/library/de...ringtopic2.asp

    There is a more detailed explanation there of the Double.ToString method.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Always display 2 digits after decimal point

    ya just found a good link there http://www.programmers-corner.com/sourcecode/125
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

Posting Permissions

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



Click Here to Expand Forum to Full Width