Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round Function

Status
Not open for further replies.

myrgir

Programmer
Feb 7, 2006
62
CA
This is a Round Function to the second digit that I made.
When I send 0.054
I want that it returns 0.05
and when I send 0.055
I want that it returns 0.06

I tought it was working fine but now I saw that:

I send 30.24 to this and it return me 30.23

Here is my function:
Public Function RoundAll(ByVal chiffre As Decimal) As Decimal
Dim digit As Integer
digit = (chiffre * 1000) Mod 10 - (((chiffre * 1000) Mod 10) Mod 1)

Dim temp As Decimal
temp = (chiffre / 0.001) Mod 1000000000000 - (((chiffre / 0.001) Mod 1000000000000) Mod 1)
temp = (temp / 10) - ((temp / 10) Mod 1)
temp = temp / 100

If digit >= 5 Then
chiffre = temp + 0.01
Else
chiffre = temp
End If
Return chiffre

To this line "temp = (chiffre / 0.001) Mod 1000000000000 - (((chiffre / 0.001) Mod 1000000000000) Mod 1)", I check what temp variable contain and it's 30239, I don't understand...

Can somebody help me?
 
Isn't this how the Round method is supposed to work (Decimal.Round or Math.Round)?

[tt]dim d as decimal = 0.054
messagebox.show(math.round(d, 2).tostring)[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top