Solved

# Decimals and rounding off

Posted on 2004-09-20

I am trying to calculate the number of pages in a repeater based on the records returned and page size, but am having issue with decimals and rounding off. e.g.

iRecordCount = 18;

iPageSize = 10;

// Get total pages

decimal dPageRecords = Convert.ToDecimal(iRecordCount / iPageSize);

iTotalPages = Convert.ToInt32(System.Math.Round(dPageRecords));

Trace.Warn("dPageRecords=" + dPageRecords.ToString());

Trace.Warn("iTotalPages=" + iTotalPages);

Output I'm looking for is:

dPageRecords=1.8

iTotalPages=2

Whereas I keep fricking getting:

dPageRecords=1

iTotalPages=1

Any ideas thanks?