mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Add template func FormatFloat https://github.com/siyuan-note/siyuan/issues/11158
This commit is contained in:
parent
032c1e2dc6
commit
52850a6387
1 changed files with 9 additions and 0 deletions
|
|
@ -120,6 +120,15 @@ func RemoveRedundantSpace(str string) string {
|
||||||
|
|
||||||
func Convert2Float(s string) (float64, bool) {
|
func Convert2Float(s string) (float64, bool) {
|
||||||
s = gulu.Str.RemoveInvisible(s)
|
s = gulu.Str.RemoveInvisible(s)
|
||||||
|
s = strings.ReplaceAll(s, " ", "")
|
||||||
|
s = strings.ReplaceAll(s, ",", "")
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
for _, r := range s {
|
||||||
|
if unicode.IsDigit(r) || '.' == r {
|
||||||
|
buf.WriteRune(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s = buf.String()
|
||||||
ret, err := strconv.ParseFloat(strings.TrimSpace(s), 64)
|
ret, err := strconv.ParseFloat(strings.TrimSpace(s), 64)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return 0, false
|
return 0, false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue