From 5234e9bce563317e9227c1f3a036f7007e9c50bb Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 30 Jul 2021 17:36:31 +0200 Subject: [PATCH] still round numbers when not formatting them (#9653) --- src/common/string/format_number.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/string/format_number.ts b/src/common/string/format_number.ts index a921ee50c4..01279cb715 100644 --- a/src/common/string/format_number.ts +++ b/src/common/string/format_number.ts @@ -1,4 +1,5 @@ import { FrontendLocaleData, NumberFormat } from "../../data/translation"; +import { round } from "../number/round"; export const numberFormatToLocale = ( localeOptions: FrontendLocaleData @@ -60,7 +61,12 @@ export const formatNumber = ( ).format(Number(num)); } } - return num.toString(); + if (typeof num === "string") { + return num; + } + return `${round(num, options?.maximumFractionDigits).toString()}${ + options?.style === "currency" ? ` ${options.currency}` : "" + }`; }; /**