Link to home
Start Free TrialLog in
Avatar of indy500fan
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!!!
Avatar of oleggold
oleggold
Flag of United States of America image

Hi indy500fan,
You can do it with double datatype conversion,I'll work on it
Hope It helps
Cheers!
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
SOLUTION
Avatar of oleggold
oleggold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of S-Twilley
S-Twilley

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
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry BriCrowe....didn't refresh.
Avatar of indy500fan

ASKER

Wow, that's a lot of input.

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
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?
sure... since you put it like that :P
too funny!