By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,909 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,909 IT Pros & Developers. It's quick & easy.

Some decimal math.

P: n/a
int sqrft = 1335;
decimal pricePerSqr = 18.33m;
decimal pricePerYear = Math.Round(pricePerSqr * sqrft, 2,
MidpointRounding.AwayFromZero);
decimal pricePerMonth = Math.Round(pricePerYear / 12, 2,
MidpointRounding.AwayFromZero);

Console.WriteLine("/Sqr:"+pricePerSqr.ToString());
Console.WriteLine("/Year:"+pricePerYear.ToString());
Console.WriteLine("/Mth:"+pricePerMonth.ToString());

// Find PricePerSqr given PerMonth.
pricePerMonth = 2039.21m;
pricePerYear = pricePerMonth * 12;
pricePerSqr = Math.Round(pricePerYear / sqrft, 2,
MidpointRounding.AwayFromZero);

Console.WriteLine("-----------");
Console.WriteLine("/Sqr:"+pricePerSqr.ToString());
Console.WriteLine("/Year:"+pricePerYear.ToString());
Console.WriteLine("/Mth:"+pricePerMonth.ToString());

/Sqr:18.33
/Year:24470.55
/Mth:2039.21
-----------
/Sqr:18.33
/Year:24470.52
/Mth:2039.21

Should I be doing something different to make both ways add up the same.
Notice the Year price is slightly different when backing in from
pricePerMonth. TIA

--
William Stacey [MVP]

Jun 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
William Stacey [MVP] wrote:
int sqrft = 1335;
decimal pricePerSqr = 18.33m;
decimal pricePerYear = Math.Round(pricePerSqr * sqrft, 2,
MidpointRounding.AwayFromZero);
decimal pricePerMonth = Math.Round(pricePerYear / 12, 2,
MidpointRounding.AwayFromZero);

Console.WriteLine("/Sqr:"+pricePerSqr.ToString());
Console.WriteLine("/Year:"+pricePerYear.ToString());
Console.WriteLine("/Mth:"+pricePerMonth.ToString());

// Find PricePerSqr given PerMonth.
pricePerMonth = 2039.21m;
pricePerYear = pricePerMonth * 12;
pricePerSqr = Math.Round(pricePerYear / sqrft, 2,
MidpointRounding.AwayFromZero);

Console.WriteLine("-----------");
Console.WriteLine("/Sqr:"+pricePerSqr.ToString());
Console.WriteLine("/Year:"+pricePerYear.ToString());
Console.WriteLine("/Mth:"+pricePerMonth.ToString());

/Sqr:18.33
/Year:24470.55
/Mth:2039.21
-----------
/Sqr:18.33
/Year:24470.52
/Mth:2039.21

Should I be doing something different to make both ways add up the same.
Notice the Year price is slightly different when backing in from
pricePerMonth. TIA


Either increase the decimal places of pricePerMonth or ALWAYS calculate
from the lowest unit ie, always start at pricePerMonth (or
perweek/perday/perhour etc..)

HTH
JB
Jun 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.