如何在 MySQL 查詢中將整數格式化為貨幣?

Barbara Streisand
發布: 2024-11-14 17:36:02
原創
398 人瀏覽過

How to Format Integers as Currency in MySQL Queries?

Converting Integers to Currency Format in MySQL Queries

In MySQL, you can transform integer values into currency format while performing selections. While you can append the currency symbol using the CONCAT() function, inserting the comma separators for large numbers requires a more elaborate approach.

Using the FORMAT() Function

The FORMAT() function provides a comprehensive solution for formatting numbers, including conversion to currency format.

Syntax:

FORMAT(val, decimals)
登入後複製

Where:

  • val is the integer value you want to convert.
  • decimals specifies the number of decimal places to display.

Example:

To convert the integer 1000 into the currency format "$1,000":

SELECT CONCAT('$', FORMAT(1000, 2)) AS formatted_value;
登入後複製

This query returns the value "$1,000". The FORMAT() function adds the commas as necessary, ensuring a professional currency display.

以上是如何在 MySQL 查詢中將整數格式化為貨幣?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板