Skip to content

Commit

Permalink
doc: rename parameter name of Comma
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Sep 27, 2024
1 parent adf18a2 commit 30eb2c7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ import "github.com/duke-git/lancet/v2/formatter"

#### Function list:

- **<big>Comma</big>** : add comma to a number value by every 3 numbers from right, ahead by symbol char.
- **<big>Comma</big>** : add comma to a number value by every 3 numbers from right, ahead by a prefix symbol char.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/formatter.md#Comma)]
[[play](https://go.dev/play/p/eRD5k2vzUVX)]
- **<big>Pretty</big>** : pretty print data to JSON string.
Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ import "github.com/duke-git/lancet/v2/formatter"

#### 函数列表:

- **<big>Comma</big>** : 用逗号每隔 3 位分割数字/字符串,支持前缀添加符号
- **<big>Comma</big>** : 用逗号每隔 3 位分割数字/字符串,支持添加前缀符号
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/formatter.md#Comma)]
[[play](https://go.dev/play/p/eRD5k2vzUVX)]
- **<big>Pretty</big>** : 返回 pretty JSON 字符串。
Expand Down
4 changes: 2 additions & 2 deletions docs/api/packages/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import (

### <span id="Comma">Comma</span>

<p>用逗号每隔3位分割数字/字符串,支持前缀添加符号。参数value必须是数字或者可以转为数字的字符串, 否则返回空字符串</p>
<p>用逗号每隔3位分割数字/字符串,支持添加前缀符号。参数value必须是数字或者可以转为数字的字符串, 否则返回空字符串</p>

<b>函数签名:</b>

```go
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
func Comma[T constraints.Float | constraints.Integer | string](value T, prefixSymbol string) string
```

<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
Expand Down
4 changes: 2 additions & 2 deletions docs/en/api/packages/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import (

### <span id="Comma">Comma</span>

<p>Add comma to a number value by every 3 numbers from right to left. ahead by symbol char. if value is a invalid number string like "aa", return empty string.</p>
<p>Add comma to a number value by every 3 numbers from right to left. ahead by a prefix symbol char. if value is a invalid number string like "aa", return empty string.</p>

<b>Signature:</b>

```go
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
func Comma[T constraints.Float | constraints.Integer | string](value T, prefixSymbol string) string
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
Expand Down
6 changes: 3 additions & 3 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"golang.org/x/exp/constraints"
)

// Comma add comma to a number value by every 3 numbers from right. ahead by symbol char.
// Comma add comma to a number value by every 3 numbers from right. ahead by prefix symbol char.
// if value is invalid number string eg "aa", return empty string
// Comma("12345", "$") => "$12,345", Comma(12345, "$") => "$12,345"
// Play: https://go.dev/play/p/eRD5k2vzUVX
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string {
func Comma[T constraints.Float | constraints.Integer | string](value T, prefixSymbol string) string {
numString := convertor.ToString(value)

_, err := strconv.ParseFloat(numString, 64)
Expand All @@ -45,7 +45,7 @@ func Comma[T constraints.Float | constraints.Integer | string](value T, symbol s
numString = "-" + numString
}

return symbol + numString
return prefixSymbol + numString
}

// Pretty data to JSON string.
Expand Down

0 comments on commit 30eb2c7

Please sign in to comment.