This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new d89e03a74ce [fix](function) add format_round function function (#2260) d89e03a74ce is described below commit d89e03a74ceec36c556e3a1bac2aaab0a99fac3a Author: Tiewei Fang <ftw2...@163.com> AuthorDate: Wed Apr 9 15:43:30 2025 +0800 [fix](function) add format_round function function (#2260) ## Versions related pr: https://github.com/apache/doris/pull/49084 - [x] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../numeric-functions/format-round.md | 123 +++++++++++++++++++ .../numeric-functions/format-round.md | 126 ++++++++++++++++++++ .../numeric-functions/format-round.md | 130 +++++++++++++++++++++ .../numeric-functions/format-round.md | 130 +++++++++++++++++++++ sidebars.json | 1 + .../numeric-functions/format-round.md | 127 ++++++++++++++++++++ .../numeric-functions/format-round.md | 127 ++++++++++++++++++++ versioned_sidebars/version-2.1-sidebars.json | 1 + versioned_sidebars/version-3.0-sidebars.json | 1 + 9 files changed, 766 insertions(+) diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..aa1cd0e3c6a --- /dev/null +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,123 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## Description + +Formats a number in a format similar to "#,###,###.##", rounds to the specified decimal places, and returns the result as a string. + +## Syntax + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<number>` | The number to be formatted | +| `<D>` | Number of decimal places | + +## Return Value + +Returns the formatted string. Special cases: + +- Returns NULL when the parameter is NULL +- If D is 0, the result will have no decimal point or decimal part. + +## Examples + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..cb3c0452e7d --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,126 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将数字格式化为类似于“#,###,###.##”的格式,四舍五入到指定位小数,并将结果作为字符串返回。 + +## 语法 + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<number>` | 需要被格式化的数字 | +| `<D>` | 小数位数 | + +## 返回值 + +返回格式化后的字符串。特殊情况: + +- 当参数为 NULL 时,返回 NULL +- 如果 D 为 0,结果将没有小数点或小数部分。 + +## 举例 + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + + + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..d47e81fca00 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,130 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将数字格式化为类似于“#,###,###.##”的格式,四舍五入到指定位小数,并将结果作为字符串返回。 + +:::tip +该函数自 2.1.10 版本开始支持. +::: + +## 语法 + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<number>` | 需要被格式化的数字 | +| `<D>` | 小数位数 | + +## 返回值 + +返回格式化后的字符串。特殊情况: + +- 当参数为 NULL 时,返回 NULL +- 如果 D 为 0,结果将没有小数点或小数部分。 + +## 举例 + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + + + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..1c4e54aef02 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,130 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将数字格式化为类似于“#,###,###.##”的格式,四舍五入到指定位小数,并将结果作为字符串返回。 + +:::tip +该函数自 3.0.6 版本开始支持. +::: + +## 语法 + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<number>` | 需要被格式化的数字 | +| `<D>` | 小数位数 | + +## 返回值 + +返回格式化后的字符串。特殊情况: + +- 当参数为 NULL 时,返回 NULL +- 如果 D 为 0,结果将没有小数点或小数部分。 + +## 举例 + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + + + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` diff --git a/sidebars.json b/sidebars.json index 3774d2879ce..baa59259046 100644 --- a/sidebars.json +++ b/sidebars.json @@ -928,6 +928,7 @@ "sql-manual/sql-functions/scalar-functions/numeric-functions/floor", "sql-manual/sql-functions/scalar-functions/numeric-functions/fmod", "sql-manual/sql-functions/scalar-functions/numeric-functions/money-format", + "sql-manual/sql-functions/scalar-functions/numeric-functions/format-round", "sql-manual/sql-functions/scalar-functions/numeric-functions/tan", "sql-manual/sql-functions/scalar-functions/numeric-functions/tanh", "sql-manual/sql-functions/scalar-functions/numeric-functions/pmod", diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..4f9c14a92e4 --- /dev/null +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,127 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## Description + +Formats a number in a format similar to "#,###,###.##", rounds to the specified decimal places, and returns the result as a string. + +:::tip +This function has been supported since version 2.1.10. +::: + +## Syntax + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<number>` | The number to be formatted | +| `<D>` | Number of decimal places | + +## Return Value + +Returns the formatted string. Special cases: + +- Returns NULL when the parameter is NULL +- If D is 0, the result will have no decimal point or decimal part. + +## Examples + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md new file mode 100644 index 00000000000..3f7c9bd3476 --- /dev/null +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/format-round.md @@ -0,0 +1,127 @@ +--- +{ + "title": "FORMAT_ROUND", + "language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## Description + +Formats a number in a format similar to "#,###,###.##", rounds to the specified decimal places, and returns the result as a string. + +:::tip +This function has been supported since version 3.0.6. +::: + +## Syntax + +```sql +FORMAT_ROUND(<number>, <D>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<number>` | The number to be formatted | +| `<D>` | Number of decimal places | + +## Return Value + +Returns the formatted string. Special cases: + +- Returns NULL when the parameter is NULL +- If D is 0, the result will have no decimal point or decimal part. + +## Examples + +```sql +mysql> select format_round(17014116, 2); ++---------------------------+ +| format_round(17014116, 2) | ++---------------------------+ +| 17,014,116.00 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.456, 2); ++---------------------------+ +| format_round(1123.456, 2) | ++---------------------------+ +| 1,123.46 | ++---------------------------+ +``` + +```sql +mysql> select format_round(1123.4, 2); ++-------------------------+ +| format_round(1123.4, 2) | ++-------------------------+ +| 1,123.40 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 0); ++-------------------------+ +| format_round(123456, 0) | ++-------------------------+ +| 123,456 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456, 3); ++-------------------------+ +| format_round(123456, 3) | ++-------------------------+ +| 123,456.000 | ++-------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 0); ++--------------------------------+ +| format_round(123456.123456, 0) | ++--------------------------------+ +| 123,456 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 3); ++--------------------------------+ +| format_round(123456.123456, 3) | ++--------------------------------+ +| 123,456.123 | ++--------------------------------+ +``` + +```sql +mysql> select format_round(123456.123456, 6); ++--------------------------------+ +| format_round(123456.123456, 6) | ++--------------------------------+ +| 123,456.123456 | ++--------------------------------+ +``` \ No newline at end of file diff --git a/versioned_sidebars/version-2.1-sidebars.json b/versioned_sidebars/version-2.1-sidebars.json index c5a2165e1c5..de4f5f76853 100644 --- a/versioned_sidebars/version-2.1-sidebars.json +++ b/versioned_sidebars/version-2.1-sidebars.json @@ -940,6 +940,7 @@ "sql-manual/sql-functions/scalar-functions/numeric-functions/floor", "sql-manual/sql-functions/scalar-functions/numeric-functions/fmod", "sql-manual/sql-functions/scalar-functions/numeric-functions/money-format", + "sql-manual/sql-functions/scalar-functions/numeric-functions/format-round", "sql-manual/sql-functions/scalar-functions/numeric-functions/tan", "sql-manual/sql-functions/scalar-functions/numeric-functions/tanh", "sql-manual/sql-functions/scalar-functions/numeric-functions/pmod", diff --git a/versioned_sidebars/version-3.0-sidebars.json b/versioned_sidebars/version-3.0-sidebars.json index ac7567adc1b..cc357838c1b 100644 --- a/versioned_sidebars/version-3.0-sidebars.json +++ b/versioned_sidebars/version-3.0-sidebars.json @@ -987,6 +987,7 @@ "sql-manual/sql-functions/scalar-functions/numeric-functions/floor", "sql-manual/sql-functions/scalar-functions/numeric-functions/fmod", "sql-manual/sql-functions/scalar-functions/numeric-functions/money-format", + "sql-manual/sql-functions/scalar-functions/numeric-functions/format-round", "sql-manual/sql-functions/scalar-functions/numeric-functions/tan", "sql-manual/sql-functions/scalar-functions/numeric-functions/tanh", "sql-manual/sql-functions/scalar-functions/numeric-functions/pmod", --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org