You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return a number formatted to specified number of decimal places.
443
+
The `FORMAT(X,D[,locale])` function is used to format the number`X` to a format similar to `"#,###,###. ##"`, rounded to `D`decimal places, and return the result as a string.
444
+
445
+
Arguments:
446
+
447
+
-`X`: the number to be formatted. It can be a direct numeric value, a numeric string, or a numberin scientific notation.
448
+
-`D`: the number of decimal places for the returned value. The function rounds the number`X` to `D`decimal places. If `D` is greater than the actual number of decimal places in`X`, the result is padded with zeros to the corresponding length.
449
+
`[locale]`: specifies a locale setting to be used for grouping between decimal points, thousands separators, and separators for resultant numbers. A valid locale value is the same as the valid value of the [`lc_time_names`](https://dev.mysql.com/doc/refman/8.3/en/server-system-variables.html#sysvar_lc_time_names) system variable. If not specified or the region setting is `NULL`, the `'en_US'` region setting is used by default. This argument is optional.
450
+
451
+
Behaviors:
452
+
453
+
- If the first argument is a string and contains only numbers, the function returns a result based on that numeric value. For example, `FORMAT('12.34', 1)`and`FORMAT(12.34, 1)` return the same result.
454
+
- If the first argument is a number represented in scientific notation (using `E/e`), the function returns the result based on that number. For example, `FORMAT('1E2', 3)` returns `100.000`.
455
+
- If the first argument is a string starting with non-numeric characters, the function returns zero and a warning `(Code 1292)`. For example, `FORMAT('q12.36', 5)` returns `0.00000`, but also includes a warning `Warning (Code 1292): Truncated incorrect DOUBLE value: 'q12.36'`.
456
+
- If the first argument is a string mixing numbers and non-numbers, the function returns a result based on the consecutive numeric part at the beginning of the argument, and also includes a warning `(Code 1292)`. For example, `FORMAT('12.36q56.78', 1)` returns the same numeric result as`FORMAT('12.36', 1)`, but includes a warning `Warning (Code 1292): Truncated incorrect DOUBLE value: '12.36q56.78'`.
457
+
- If the second argument is zero or a negative number, the function truncates the decimal part and returns an integer.
458
+
- If any of the arguments is `NULL`, the function returns `NULL`.
459
+
460
+
Examples:
461
+
462
+
The following examples show how to format the number12.36 to different decimal places:
The `FROM_BASE64()` function is used to decode a [Base64](https://datatracker.ietf.org/doc/html/rfc4648) encoded string and return the decoded result in its hexadecimal form.
494
+
495
+
- This function accepts a single argument, that is, the Base64 encoded string to be decoded.
496
+
- If the argument is `NULL`or not a valid Base64 encoded string, the `FROM_BASE64()` function returns `NULL`.
497
+
498
+
Examples:
499
+
500
+
The following example shows how to decode the Base64 encoded string `'SGVsbG8gVGlEQg=='`. This string is the result of encoding `'Hello TiDB'`, using the [`TO_BASE64()`](#to_base64) function.
The following example shows how to decode the Base64 encoded number`MTIzNDU2`. This string is the result of encoding `123456`, which can be done using the [`TO_BASE64()`](#to_base64) function.
0 commit comments