Click to See Complete Forum and Search --> : rounding numbers


Dr_Michael
January 12th, 2000, 03:29 AM
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

Dr_Michael
January 12th, 2000, 03:33 AM
... 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

Lothar Haensler
January 12th, 2000, 03:42 AM
ONE possible solution:
Dim number As Double
number = 1344.78
MsgBox Format(number, "#,###.##")

Lothar Haensler
January 12th, 2000, 03:50 AM
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

Dr_Michael
January 12th, 2000, 03:58 AM
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

Lothar Haensler
January 12th, 2000, 03:59 AM
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

Dr_Michael
January 12th, 2000, 05:33 AM
It worked!!!!! Can I rate you again? ;-)

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

Lothar Haensler
January 12th, 2000, 06:13 AM
>...Can I rate you again? ;-)

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