title: Logic in Custom Rounding off - VB Script - QTP
body: <p>I have a data file where decimal points aren't specified for a decimal number. The number is just described in the layout for the data file as first 2 digits as real and next 2 digits as decimal and it varies for different fields, the real and decimal part</p>
  
  <p>So an actual number 12345.6789 is specified as 123456789. When I want this to be rounded off to 2 decimal points to match the value in application, I use the below logic</p>
  
  <pre><code>Public Function Rounding(NumberValue, DecimalPoints, RoundOff)
  
          Rounder= Roundoff+1
      Difference = DecimalPoints - Rounder
      NumberValue = Mid(NumberValue, 1, Len(NumberValue)-Difference)
  
      RealNumber=Mid(NumberValue,1,Len(NumberValue)-Rounder)
      DecimalNumber=Right(NumberValue,Rounder)
  
      NumberValue = RealNumber&amp;"."&amp;DecimalNumber
      NumberValue = Cdbl(NumberValue)
      NumberValue = Round(NumberValue, Roundoff)
      Rounding = FormatNumber(NumberValue,Difference+1,,,0)
  
  End Function
  </code></pre>
  
  <p>However the problem with this logic is that I am not able to round off decimals when the number has 0 as the decimal value</p>
  
  <p>For an Example, lets take 12345.0000 which I want to round off to 2 decimal points</p>
  
  <p>My function returns it as 12345 whereas I want this to be returned as 12345.00</p>
  
  <p>Any ideas on how this logic could be tweaked to get the desired output or is that not possible at all?</p>