From d70c4f4623a47a226056188474e3cc5b5ecbabfc Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Thu, 19 Jul 2012 13:27:38 -0700 Subject: [PATCH] fix float to decimal conversion in stats --- mkt/stats/search.py | 2 +- mkt/stats/tests/test_tasks.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mkt/stats/search.py b/mkt/stats/search.py index af95b269693..0641a294cfb 100644 --- a/mkt/stats/search.py +++ b/mkt/stats/search.py @@ -203,7 +203,7 @@ def cut(revenue): """ Takes away Marketplace's cut from developers' revenue. """ - return Decimal(round(Decimal(revenue) * Decimal(MKT_CUT), 2)) + return Decimal(str(round(revenue * MKT_CUT, 2))) def handle_kwargs(q, field, kwargs, join_field=None): diff --git a/mkt/stats/tests/test_tasks.py b/mkt/stats/tests/test_tasks.py index 76c2c6ae81d..166552e646c 100644 --- a/mkt/stats/tests/test_tasks.py +++ b/mkt/stats/tests/test_tasks.py @@ -1,4 +1,5 @@ import datetime +from decimal import Decimal import random from django.utils import unittest @@ -428,7 +429,7 @@ def test_basic(self): class TestCut(unittest.TestCase): def test_basic(self): - eq_(cut(0), 0) - eq_(cut(1), .7) - eq_(cut(10), 7) - eq_(cut(33), 23.10) + eq_(cut(0), Decimal(str(0))) + eq_(cut(1), Decimal(str(.7))) + eq_(cut(10), Decimal(str(7))) + eq_(cut(33), Decimal(str(23.10)))