I am an engineering intern and am trying to write a program that will convert metric dimensions and tolerances to imperial. When making this conversion the tolerance must be smaller than the metric. How can I round my converted tolerance down? I do not want to floor my value. This is c++ incase i needed to specify
I'll give you an example of what I mean. Also, by imperial I mean inches - sorry about that.
Lets say that we have 4 mm and we want to convert it to inches. The math would be
4 mm * (1/25.4) = 0.15748 inches
If I want this converted number to be used as a tolerance, it has to be either 3 or 4 decimal places(shown as k in the code above). This is because machines that use these dimensions can only go down to a 4 decimal place precision before they become inaccurate.
So rather than rounding up a tolerance to ± 0.1575, I need to make the tolerance smaller ie, round the decimal place down - to ± 0.1574.
No problem, that's why I asked because I had an inkling that was the issue.
What you do is convert to 1/1000's or 1/10,000's round that and then do the division by 1000 or 10000 or whatever.
So if your unit it 1/10000 multiply .15748 by 10000 = 1574.8 round down to 1574 then ... tada you have .1574" (1574/10000) which is what I gather you are looking for.
Yeah i'm having issues trying to wrap my head around re-declaring a converted tolerance as an integer to truncate, then to push it back to a double so that it can be output as a decimal.
I think this may be a simpler way to approach this problem. I'll give it a shot.
I think this may be a simpler way to approach this problem. I'll give it a shot.
Unfortunately, the approach doesn't offer a solution. All it does is affect the way the textual representation is formatted when the value is inserted into a stream.
Can you explain to me why my code didn't work as intended? I am confused.
Probably a QOI issue. I can't look right now, but I don't believe the standard requires streams to honor the rounding specified in those co-opted C functions.