Files
2026-05-20 16:13:58 +08:00

40 lines
900 B
Go
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package botser
import (
"fmt"
"math"
)
func Rate(temp string, numerator, denominator float64) string {
fZero := math.Pow10(-10)
if math.Abs(denominator) < fZero {
return fmt.Sprintf(temp, "无") + "\n"
} else {
str := fmt.Sprintf("%.2f%%", numerator*100/denominator)
return fmt.Sprintf(temp, str) + "\n"
}
}
func Line(iTemp string, iValue int64, numerator, denominator float64) string {
fZero := math.Pow10(-10)
if math.Abs(denominator) < fZero {
s1 := fmt.Sprintf("%d", iValue)
str1 := fmt.Sprintf(iTemp, s1)
return str1 + "\n"
} else {
s1 := fmt.Sprintf("%d", iValue)
str1 := fmt.Sprintf(iTemp, s1)
v := numerator * 100 / denominator
str2 := ""
if v < 0 {
str2 = fmt.Sprintf("⬇-️️%.2f%%", math.Abs(v))
} else if v > 0 {
str2 = fmt.Sprintf("⬆+️%.2f%%", math.Abs(v))
}
if str2 == "" {
return str1 + "\n"
}
return str1 + str2 + "\n"
}
}