mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-24 09:38:35 +02:00
initial commit
This commit is contained in:
0
app/apps/common/functions/__init__.py
Normal file
0
app/apps/common/functions/__init__.py
Normal file
13
app/apps/common/functions/decimals.py
Normal file
13
app/apps/common/functions/decimals.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
|
||||
|
||||
def truncate_decimal(value, decimal_places):
|
||||
"""
|
||||
Truncate a Decimal value to n decimal places without rounding.
|
||||
|
||||
:param value: The Decimal value to truncate
|
||||
:param decimal_places: The number of decimal places to keep
|
||||
:return: Truncated Decimal value
|
||||
"""
|
||||
multiplier = Decimal(10**decimal_places)
|
||||
return (value * multiplier).to_integral_value(rounding=ROUND_DOWN) / multiplier
|
||||
Reference in New Issue
Block a user