CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    rounding numbers

    I want to round a number with no decimals, so I use:

    Round(MyNumber, 0)



    I want to ask you how can I add a digit grouping "." ?
    eg. if MyNumber = 1344,78 I want to be displayed as: "1.344,78"
    How can I achieve this?

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  2. #2
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    And one more:

    ... These numbers are displayed in a ListView column and when I try to sort them, it sorts them as text and not numbers, like this way:
    105
    11
    1131
    123

    But the right order should be:
    11
    105
    123
    1131

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: rounding numbers

    ONE possible solution:
    Dim number As Double
    number = 1344.78
    MsgBox Format(number, "#,###.##")



  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: And one more:

    Listview sorts columns as Text.
    One possible solution:
    - add your values into two separate columns
    - make one column invisible (width = 0)
    - add a formatted value to the invisible column (l.subitems(1)= format(...)) [format that column in a way that causes correct sort order when sorted as Test]
    - sort the listview on that invisible column


  5. #5
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Well,

    about my first question:
    it worked with this:

    Format(Round(MyNumber, 0), "#,###")



    Thanx!

    about the second question now:
    your solution is very clever, I'll try it out and let you know. But I would love an easier way of doing that. Anyway, thak you
    P.S. Lothar, check your private messages please!

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  6. #6
    Join Date
    May 1999
    Posts
    3,332

    use Format for rounding number

    you can also use the format function for rounding!
    Try these:

    Dim number as Double
    number = 1344.774
    MsgBox Format(number, "#,###.##")

    number = 1344.776
    MsgBox Format(number, "#,###.##")




    ...will yield 1344.77 and 1344.78


  7. #7
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: And one more:

    It worked!!!!! Can I rate you again? ;-)

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  8. #8
    Join Date
    May 1999
    Posts
    3,332

    Re: And one more:

    >...Can I rate you again? ;-)

    go ahead. If it doesn't work, send money! ;-)


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

Featured