🎨 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) {
|
||||
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)
|
||||
if nil != err {
|
||||
return 0, false
|
||||
|
|
Loading…
Add table
Reference in a new issue