tag: use as_float() when kb/mb/gb formatting a float tag value

This commit is contained in:
Daniel Eklöf 2022-06-02 21:33:04 +02:00
parent c738f1c63d
commit de4814d16e
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 9 additions and 3 deletions

View file

@ -31,6 +31,9 @@
### Changed ### Changed
* Minimum required meson version is now 0.58. * Minimum required meson version is now 0.58.
* Float tags are now treated as floats instead of integers when
formatted with the `kb`/`kib`/`mb`/`mib`/`gb`/`gib` string particle
formatters.
* **BREAKING CHANGE**: overhaul of the `map` particle. Instead of * **BREAKING CHANGE**: overhaul of the `map` particle. Instead of
specifying a `tag` and then an array of `values`, you must now specifying a `tag` and then an array of `values`, you must now
simply use an array of `conditions`, that consist of: simply use an array of `conditions`, that consist of:

3
tag.c
View file

@ -582,6 +582,9 @@ tags_expand_template(const char *template, const struct tag_set *tags)
1; 1;
char str[24]; char str[24];
if (tag->type(tag) == TAG_TYPE_FLOAT)
snprintf(str, sizeof(str), "%f", tag->as_float(tag) / (double)divider);
else
snprintf(str, sizeof(str), "%lu", tag->as_int(tag) / divider); snprintf(str, sizeof(str), "%lu", tag->as_int(tag) / divider);
sbuf_append(&formatted, str); sbuf_append(&formatted, str);
break; break;