-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove human friendly digit group separators #141
base: master
Are you sure you want to change the base?
Remove human friendly digit group separators #141
Conversation
Signed-off-by: Zach Leinweber <[email protected]>
e392410
to
c55a252
Compare
@@ -34,6 +35,8 @@ import ( | |||
pconfig "github.com/prometheus/common/config" | |||
) | |||
|
|||
var sanitzieValueRE = regexp.MustCompile(`(,|_)`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than use a regexp, how about a string replacer?
var sanitzieValueRE = regexp.MustCompile(`(,|_)`) | |
var sanitzieValue = strings.NewReplacer(",", "", "|", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- var sanitzieValue = strings.NewReplacer(",", "", "|", "")
+ var sanitzieValue = strings.NewReplacer(",", "", "_", "")
@@ -43,7 +46,7 @@ func SanitizeValue(s string) (float64, error) { | |||
var value float64 | |||
var resultErr string | |||
|
|||
if value, err = strconv.ParseFloat(s, 64); err == nil { | |||
if value, err = strconv.ParseFloat(sanitzieValueRE.ReplaceAllString(s, ""), 64); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if value, err = strconv.ParseFloat(sanitzieValueRE.ReplaceAllString(s, ""), 64); err == nil { | |
if value, err = strconv.ParseFloat(sanitzieValue.Replace(s), 64); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings
instead of regexp
.
Ping, please resolve requested changes. |
Some APIs that return numeric values as a string that include commas or underscores to separate digit groups. For example,
"1,000"
. This causes an error inSanitizeValue
when the string gets passed intostrconv.ParseFloat()
.This fixes the problem above transparently.