MySql格式数字,以空格作为千位分隔符,不带十进制零



将数字:103,648.340格式化为预期结果

预期结果:103 648.34

我的进展:

SELECT
TRIM(price)+0 as price_without_decimal_zeros,
FORMAT(price, 1, 'bg_BG') as thousand_delimited_by_space
from products

  1. TRIM删除十进制零,所以我有103,648.34
  2. FORMAT添加以空格分隔的千位,所以我有103 648.340

我试过把TRIMFORMAT结合起来,但没有成功

试试这个解决方案:

SELECT TRIM(TRAILING '.' FROM TRIM(TRAILING '0' from REPLACE(format(price, 3), ",", " ") )) AS price
FROM products
WHERE price LIKE '%.%'

演示

相关内容

  • 没有找到相关文章

最新更新