indy500fan
asked on
How do I Trim a decimal from 57.3242456436543 to 57.324?
How do I trim a decimal to only 3 significant places?
I do the calculation:
Speed = Distance / ElapsedTime
and I might get 57.3242456436543 for example.
Then, as the very next line of code, I have:
Math.Round(Speed, 3)
Now, when I display Speed, has that number been rounded (meaning anytime I reference Speed it is 57.324, until it is recalculated), or should I do it within the calculation?
Unfortunately, I can't test this, and I won't be able to until tomorrow. That is why I am asking you experts in hopes that you can test it for me. This is fairly urgent so I'm putting up 500points.
Thanks in advance!!!
I do the calculation:
Speed = Distance / ElapsedTime
and I might get 57.3242456436543 for example.
Then, as the very next line of code, I have:
Math.Round(Speed, 3)
Now, when I display Speed, has that number been rounded (meaning anytime I reference Speed it is 57.324, until it is recalculated), or should I do it within the calculation?
Unfortunately, I can't test this, and I won't be able to until tomorrow. That is why I am asking you experts in hopes that you can test it for me. This is fairly urgent so I'm putting up 500points.
Thanks in advance!!!
This worked fine for me:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim s As Date = CDate(Me.TextBox1.Text)
'i += 1
'Me.TextBox1.Text = i
'Dim ds As System.Data.DataSet
'Me.ListBox1.MultiColumn = True
'Me.ListBox1.DataSource = ds
Dim d As Double = 57.3242456436543
Dim dd As Double
dd = Math.Round(d, 2)
Me.ListBox1.Items.Add(d & " to " & dd)
Me.ListBox1.Items.Add(":" & dd)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim s As Date = CDate(Me.TextBox1.Text)
'i += 1
'Me.TextBox1.Text = i
'Dim ds As System.Data.DataSet
'Me.ListBox1.MultiColumn = True
'Me.ListBox1.DataSource = ds
Dim d As Double = 57.3242456436543
Dim dd As Double
dd = Math.Round(d, 2)
Me.ListBox1.Items.Add(d & " to " & dd)
Me.ListBox1.Items.Add(":" & dd)
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What's the problem,pls explain it more detailed,Thanks
When You are displaying it's has been rounded (in my listbox for sure) for any number of displays
Just for reading, this question is still open and I've posted an alternative to using the Round method (the user stated their own problems with using that method).
https://www.experts-exchange.com/questions/21321033/Rounding-upto-two-decimals.html
https://www.experts-exchange.com/questions/21321033/Rounding-upto-two-decimals.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry BriCrowe....didn't refresh.
ASKER
Wow, that's a lot of input.
Thanks to all of you. How do I split the points on this one???
Thanks to all of you. How do I split the points on this one???
Think you should just split it up amongst the people who helped you to come to your conclusion/answer... Im not fussed as I only referred you to a "discussion" so it was kinda cheating :P
ASKER
Okay guys, here's my reasoning:
oleggold - I gave you 225 because you gave me a means of troubleshooting with yours.
BriCrowe - I gave you 225 because you gave me a reason as to your answer, and you were really heading down the path I was looking for...
Idle Mind - Even though BriCrowe beat you to the punch, you confirmed what I was suspecting...
And S-Twilley, even though you are one of my favorite experts, I felt like the other guys got there first... Still friends?
oleggold - I gave you 225 because you gave me a means of troubleshooting with yours.
BriCrowe - I gave you 225 because you gave me a reason as to your answer, and you were really heading down the path I was looking for...
Idle Mind - Even though BriCrowe beat you to the punch, you confirmed what I was suspecting...
And S-Twilley, even though you are one of my favorite experts, I felt like the other guys got there first... Still friends?
sure... since you put it like that :P
ASKER
too funny!
You can do it with double datatype conversion,I'll work on it
Hope It helps
Cheers!