當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.format_number方法代碼示例

本文整理匯總了Python中django.db.backends.utils.format_number方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.format_number方法的具體用法?Python utils.format_number怎麽用?Python utils.format_number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.backends.utils的用法示例。


在下文中一共展示了utils.format_number方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: value_to_db_decimal

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def value_to_db_decimal(self, value, max_digits, decimal_places):
        """
        Transforms a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        """
        return utils.format_number(value, max_digits, decimal_places) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:8,代碼來源:operations.py

示例2: _format

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def _format(self, value):
        if isinstance(value, six.string_types):
            return value
        else:
            return self.format_number(value) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:__init__.py

示例3: format_number

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def format_number(self, value):
        """
        Formats a number into a string with the requisite number of digits and
        decimal places.
        """
        # Method moved to django.db.backends.utils.
        #
        # It is preserved because it is used by the oracle backend
        # (django.db.backends.oracle.query), and also for
        # backwards-compatibility with any external code which may have used
        # this method.
        from django.db.backends import utils
        return utils.format_number(value, self.max_digits, self.decimal_places) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:__init__.py

示例4: adapt_decimalfield_value

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def adapt_decimalfield_value(self, value, max_digits=None, decimal_places=None):
        """
        Transform a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        """
        return utils.format_number(value, max_digits, decimal_places) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:8,代碼來源:operations.py

示例5: format_number

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def format_number(self, value):
        """
        Format a number into a string with the requisite number of digits and
        decimal places.
        """
        # Method moved to django.db.backends.utils.
        #
        # It is preserved because it is used by the oracle backend
        # (django.db.backends.oracle.query), and also for
        # backwards-compatibility with any external code which may have used
        # this method.
        from django.db.backends import utils
        return utils.format_number(value, self.max_digits, self.decimal_places) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:__init__.py

示例6: adapt_decimalfield_value

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def adapt_decimalfield_value(self, value, max_digits=None, decimal_places=None):
        """
        Transforms a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        """
        return utils.format_number(value, max_digits, decimal_places) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:8,代碼來源:operations.py

示例7: adapt_decimalfield_value

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def adapt_decimalfield_value(self, value, max_digits, decimal_places):
        """
        Transforms a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        """
        return utils.format_number(value, max_digits, decimal_places) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:8,代碼來源:operations.py

示例8: test_format_number

# 需要導入模塊: from django.db.backends import utils [as 別名]
# 或者: from django.db.backends.utils import format_number [as 別名]
def test_format_number(self):
        """
        Test the format_number converter utility
        """
        def equal(value, max_d, places, result):
            self.assertEqual(format_number(Decimal(value), max_d, places), result)

        equal('0', 12, 3,
              '0.000')
        equal('0', 12, 8,
              '0.00000000')
        equal('1', 12, 9,
              '1.000000000')
        equal('0.00000000', 12, 8,
              '0.00000000')
        equal('0.000000004', 12, 8,
              '0.00000000')
        equal('0.000000008', 12, 8,
              '0.00000001')
        equal('0.000000000000000000999', 10, 8,
              '0.00000000')
        equal('0.1234567890', 12, 10,
              '0.1234567890')
        equal('0.1234567890', 12, 9,
              '0.123456789')
        equal('0.1234567890', 12, 8,
              '0.12345679')
        equal('0.1234567890', 12, 5,
              '0.12346')
        equal('0.1234567890', 12, 3,
              '0.123')
        equal('0.1234567890', 12, 1,
              '0.1')
        equal('0.1234567890', 12, 0,
              '0')
        equal('0.1234567890', None, 0,
              '0')
        equal('1234567890.1234567890', None, 0,
              '1234567890')
        equal('1234567890.1234567890', None, 2,
              '1234567890.12')
        equal('0.1234', 5, None,
              '0.1234')
        equal('123.12', 5, None,
              '123.12')
        with self.assertRaises(Rounded):
            equal('0.1234567890', 5, None,
                  '0.12346')
        with self.assertRaises(Rounded):
            equal('1234567890.1234', 5, None,
                  '1234600000') 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:53,代碼來源:tests.py


注:本文中的django.db.backends.utils.format_number方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。