Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I want to round the actual value of a variable to a certain precision point.

Example:

.3333333333333

to

.3333300000000

(rounding to .00001)

Is this possible?

share|improve this question

closed as off topic by Marvis, Davide Giraudo, draks ..., Micah, tomasz Dec 23 '12 at 15:03

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Voting to close this as off-topic. –  user17762 Dec 23 '12 at 10:53
    
Yes, this question belongs to Stackoverflow. –  Barnabas Szabolcs Dec 23 '12 at 10:54
    
why is this off topic? –  Vigrond Dec 23 '12 at 10:54
1  
This question could have had both a programmatic solution or mathematical. It turns out the solution was mathematical. I was leaning toward wanting a mathematical solution (as my research didn't find a programmatic solution), so I posted it here. –  Vigrond Dec 23 '12 at 10:57
1  
In the FAQ, the fifth bullet says "We welcome questions about... Software that mathematicians use." –  robjohn Dec 23 '12 at 12:03
show 5 more comments

1 Answer 1

up vote 2 down vote accepted

$$ \left[ 10^5 x \right] / 10^5 $$

The idea is that $10^5$ times the rounded value of $x$ is an integer, so we simply shift the problem over so that we can ask for the nearest integer, then shift back.

share|improve this answer
    
why would you think this would work? (it doesn't) can you explain your answer? –  Vigrond Dec 23 '12 at 10:46
    
Worked for me: (grr I can't format the link correctly: you'll have to copy/paste) wolframalpha.com/input/?i=Round%28%200.333333333333333333%20*%2010%5E‌​5%29%20/%2010%5E5 –  Hurkyl Dec 23 '12 at 10:48
    
Sorry I guess I didn't understand the rounding syntax. Thanks, this works perfectly in octave. –  Vigrond Dec 23 '12 at 10:53
1  
Ah sorry. The typical symbols in mathematics notation are $\lfloor x \rfloor$ for the floor function, $\lceil x \rceil$ for the ceiling function, and $[x]$ for the nearest integer function. –  Hurkyl Dec 23 '12 at 10:54
    
@Hurkyl: where all of these characters are available, I like to use $[x]$ for nearest integer. However, for those of us who were stuck previously on ASCII only usenet forums, [x] usually meant "floor of $x$", and sometimes we get confused about its intended usage on math.SE. –  robjohn Dec 23 '12 at 17:08
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.