Skip to content

Commit

Permalink
csvtk round: fix bug of failing to round scientific notation with val…
Browse files Browse the repository at this point in the history
…ue small than one
  • Loading branch information
shenwei356 committed Jan 11, 2021
1 parent 1e4ef09 commit 344bb81
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -8,6 +8,7 @@
- new command: `csvtk unfold` for unfolding multiple values in cells of a field. [#103](https://github.com/shenwei356/csvtk/issues/103)
- rename `csvtk collapse` to `csvtk fold`, for folding multiple values of a field into cells of groups.
- `csvtk cut`: **support range format `2-` to choose 2nd column to the end**. [#106](https://github.com/shenwei356/csvtk/issues/106)
- `csvtk round`: fix bug of failing to round scientific notation with value small than one, e.g., `7.1E-1`.
- [csvtk v0.21.0](https://github.com/shenwei356/csvtk/releases/tag/v0.21.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.21.0/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.21.0)
- new command: `csvtk nrow/ncol` for printing number of rows or columns.
Expand Down
4 changes: 4 additions & 0 deletions csvtk/cmd/round.go
Expand Up @@ -26,6 +26,7 @@ import (
"regexp"
"runtime"
"strconv"
"strings"

"github.com/shenwei356/xopen"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -220,6 +221,9 @@ var roundCmd = &cobra.Command{
record2[f] = fmt.Sprintf(decimalFormat, fvalue)
} else if found[1] == "" {

} else if strings.IndexByte(found[2], '-') > 0 { // scientific notation with value < 1
fvalue, _ = strconv.ParseFloat(record2[f], 10)
record2[f] = fmt.Sprintf(decimalFormat, fvalue)
} else {
fvalue, _ = strconv.ParseFloat(found[1], 10)
record2[f] = fmt.Sprintf(decimalFormat, fvalue) + found[2]
Expand Down
1 change: 1 addition & 0 deletions doc/docs/download.md
Expand Up @@ -15,6 +15,7 @@
- new command: `csvtk unfold` for unfolding multiple values in cells of a field. [#103](https://github.com/shenwei356/csvtk/issues/103)
- rename `csvtk collapse` to `csvtk fold`, for folding multiple values of a field into cells of groups.
- `csvtk cut`: **support range format `2-` to choose 2nd column to the end**. [#106](https://github.com/shenwei356/csvtk/issues/106)
- `csvtk round`: fix bug of failing to round scientific notation with value small than one, e.g., `7.1E-1`.

Links:

Expand Down

0 comments on commit 344bb81

Please sign in to comment.