title: SQL Server : decimal difference in time
body: <p>I am trying to convert decimal hours difference in time however always round up causing problem.</p>
  
  <pre><code>declare @Accrued decimal(9,4) = 24.60
  declare @Used decimal(9,4) = 23.5734
  declare @Remaining decimal(9,2) = @Accrued -  @Used
  
  declare @RoundAccrued decimal(9,2) = ceiling(@Accrued * 100) /  100
  declare @RoundUsed decimal(9,2) =  ceiling(@Used * 100) /  100
  declare @RoundRemaining decimal(9,2) =  ceiling(@Remaining * 100) /  100
  
  declare @hrAcc int = @Accrued
  select left(cast (@hrAcc as varchar), 4) + '.' + right('0' + cast((floor((@RoundAccrued * 60) % 60)) as varchar), 2) Accrued
  
  declare @hrUsed int = @Used
  select left(cast (@hrUsed as varchar), 4) + '.' + right('0' + cast((floor((@RoundUsed * 60) % 60)) as varchar), 2) Used
  declare @hrRem int = @Remaining
  select  left(cast (@hrRem as varchar), 4) + '.' + right('0' + cast((floor((@RoundRemaining * 60) % 60)) as varchar), 2) Remaining
  </code></pre>
  
  <p>Results</p>
  
  <ul>
  <li>Accrued: 24.36</li>
  <li>Used: 23.34</li>
  <li>Remaining: 1.01 (instead of 1.02)</li>
  </ul>
  
  <p>It works perfectly on <code>Accrued</code> and <code>Used</code>, but whatever I did, it is still either one minute short or more than the different time.</p>