Could you please check the issue reported in this forum thread?
https://social.msdn.microsoft.com/Forums/en-US/aa0cd926-1bfe-40c9-925e-76607e074a6a/azure-usage-scaled-rates-pricing?forum=partnercenterapi
The price calculated by this sample code is different from Azure calculator. The key difference is in :
total = total + ((remainingUsage - LastKey + 1) * LastKeyValue);
when the remaining usage is 1, and Last Key is 0, the real result would be (1-0+1)=2, so the real usage in this command is 2, not 1.