openpodcast / api

OpenPodcast API server
https://openpodcast.dev
8 stars 2 forks source link

API problem floats are shown as strings #60

Closed woolfg closed 1 year ago

woolfg commented 1 year ago

calculated string are decimal, so it seems to be a problem in the js code while converting

WITH data as
...
SELECT
ep_guid as guid,data.spa_facet as age_group, data.listeners, ROUND(data.listeners/age_sum.listeners*100, 2) as percent
FROM data JOIN age_sum USING (episode_id) JOIN spotifyEpisodeMetadata USING (episode_id) JOIN appleEpisodeMetadata ON (spotifyEpisodeMetadata.ep_name=appleEpisodeMetadata.ep_name)

Field   4:  `percent`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     21
Max_length: 5
Decimals:   2
Flags:      BINARY NUM 
woolfg commented 1 year ago

NEWDECIMAL is handeled as string as the decimal is not the same as float. we could cast it to float by applying CAST("3.5" as FLOAT). although this is not the same as we lose precision. this is not a problem for us at the moment but I would argue the handling is correct and the client of the api can decide how to store/handle the precision. so I would vouch for not chaning it.

fyi @mre