I am trying to calculate the square root of a number to where it looks like this:
Enter number for square root: 2
---------------------------------
.41
However, with the current code I have:
def calc(self, event=None):
try:
self.result_var.set("The square root of %s is %0.2f" % \
(self.number.get(), sqrt(float(self.number.get()))) )
I get 1.41.
How do I remove the "1" so it only displays ".41?"
num - int(num), just like all the oldsckool cool c kids.n % 1.% 1doesn't give the decimal part for negative numbers. That's not a concern if you're getting the number from a square root, but ... in general I suppose it could be.