# Rounding to user specific digits

Page 1 of 1

## 1 Replies - 490 Views - Last Post: 04 September 2011 - 03:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=246009&amp;s=1183286942e12c8950e084368e6f0fa7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 TheLampard80

Reputation: 0
• Posts: 1
• Joined: 04-September 11

# Rounding to user specific digits

Posted 04 September 2011 - 02:07 PM

Ok, so I have made this code that calculates the roots of a quadratic function... here it is:

``` print "ax^2 + bx + c = 0"
def quad_discriminating_roots(a, b, c, entier = 1e-5):
discriminant = b*b - 4*a*c
a,b,c,d =complex(a), complex(B)/>, complex(c), complex(discriminant)
root1 = (-b + d**0.5)/2./a
root2 = (-b - d**0.5)/2./a
x = root1
y = root2
if abs(discriminant) < entier:
return "real and equal", abs(x), abs(x)
if discriminant > 0:
return "real", x.real, y.real
return "complex", x, y

for coeffs in ((5, 2, 4/3.), (4, 6, -2), (3, 2, 1), (1.0, -10.0E5, 1.0)):
print "Roots of: %gX^2 %+gX %+g are" % coeffs
print " %s: %s, %s" % quad_discriminating_roots(*coeffs)
```

Now, I want the answers to be rounded to user specific digits (eg.
``` "%.4f" % x
```
.
I have tried putting this everywhere, but I cannot get it to work. Any thoughts?
Side question, is there any known way of replacing the imaginary unit "j" with the more traditional "i"?

Is This A Good Question/Topic? 0

## Replies To: Rounding to user specific digits

### #2 baavgai

• Dreaming Coder

Reputation: 6298
• Posts: 13,462
• Joined: 16-October 07

## Re: Rounding to user specific digits

Posted 04 September 2011 - 03:49 PM

This is one of those questions that looks like, if you actually wrote that code, you should be able to answer that question...

So, here's the code you didn't write: http://rosettacode.o...function#Python

And here's you asking the same question around the web:
http://forums.devshe...its-846110.html

You might have had something to do with the one too, but then gave up being subtle: http://www.programmi...post217673.html

Oh, wait, that is you; nothing like username consistency.

Sorry, you have to do some part of your homework on your own. Good luck with that.