use locale to format currency

This commit is contained in:
2020-10-17 08:25:56 +02:00
parent 71305e8002
commit 6bc9d34fde
4 changed files with 17 additions and 18 deletions

View File

@@ -17,12 +17,13 @@ from pyramid.httpexceptions import (
from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message, Attachment
from datetime import *
import hashlib
from sqlalchemy.exc import DBAPIError
from ..security import groupfinder
from user_agents import parse
import json
import locale
import hashlib
from ..models.default import *
from ..models.agenda import *
@@ -37,25 +38,23 @@ def to_decimal(x):
def to_euro(x):
"""Takes a float and returns a string"""
#if x == 0:
# return ""
#else:
return ("%.2f" % x).replace('.', ',')
locale.setlocale(locale.LC_ALL,'')
return locale.currency(x, True, True)
def to_euroz(x):
"""Takes a float and returns a string"""
if x == 0:
return ""
else:
return ("%9.2f" % x).replace('.', ',')
return to_euro(x)
def to_decz(x):
"""Takes a decimal and returns a string"""
"""Takes a float and returns a number with 2 dec"""
locale.setlocale(locale.LC_ALL,'')
if x == 0:
return ""
else:
return ("%.2f" % x).replace('.', ',')
return locale.format_string('%.2f',x, False)
def to_sha1(message):
return hashlib.sha1(message.encode('utf-8')).hexdigest()