R
Railway14mo ago
jeremy

Math doesn't add up for service cost

It could be a feedback thread, but maybe with the project ID it will be easier to look into it. All columns are 0$ but total is 0.0001$. They all have the same number of zeros. I guess there is some rounding involves for the display of each numbers that creates this 34849d22-d685-4e73-8858-fbd4fe42ea65
No description
6 Replies
Percy
Percy14mo ago
Project ID: 34849d22-d685-4e73-8858-fbd4fe42ea65
Fragly
Fragly14mo ago
I wonder if something like this might be the cause:
const mem = 0.000056
const cpu = 0.000053

// rounds the number in a way where the `decimals` amount displays no matter what
function getRounded(number, decimals) {
let str = Math.floor(number * 10 ** decimals) / 10 ** decimals;
let [whole, fraction = ""] = String(str).split(".");
fraction = fraction.padEnd(decimals, '0');
return `${whole}.${fraction}`;
}

// log results
console.log(`Memory Usage: $${getRounded(mem, 4)}` + "\n"
+ `CPU Usage: $${getRounded(cpu, 4)}` + "\n"
+ `Total Usage: $${getRounded(cpu + mem, 4)}`
)
const mem = 0.000056
const cpu = 0.000053

// rounds the number in a way where the `decimals` amount displays no matter what
function getRounded(number, decimals) {
let str = Math.floor(number * 10 ** decimals) / 10 ** decimals;
let [whole, fraction = ""] = String(str).split(".");
fraction = fraction.padEnd(decimals, '0');
return `${whole}.${fraction}`;
}

// log results
console.log(`Memory Usage: $${getRounded(mem, 4)}` + "\n"
+ `CPU Usage: $${getRounded(cpu, 4)}` + "\n"
+ `Total Usage: $${getRounded(cpu + mem, 4)}`
)
logs:
Memory Usage: $0.0000
CPU Usage: $0.0000
Total Usage: $0.0001
Memory Usage: $0.0000
CPU Usage: $0.0000
Total Usage: $0.0001
obviously not the same code but the same principal, the numbers in the Memory and Cpu might be getting cut off due to being too low but when added together it's enough to show a 0.0001 or the total uses round while the others only floors costs
Adam
Adam14mo ago
Looks like you’ve just kicked off your app. Railway takes ~48 hours to generate an accurate cost metric
jeremy
jeremyOP14mo ago
Then it would be better to not show the metrics at all during this time. From a user standpoint, seeing "incorrect" math and/or different display calculation for the cost is a bit weird imo
Adam
Adam14mo ago
valid feedback, i’ve forwarded to the team
jr
jr14mo ago
Railway takes ~48 hours to generate an accurate cost metric
This is not true. Service costs are real time. It is simply a rounding issue when visually showing the numbers Agree it is confusing though and that we can improve the numbers that are displayed
Want results from more Discord servers?
Add your server