main
1using gorilla.commons.utility;
2
3namespace MoMoney.Domain.Core
4{
5 static public class MoneyExtensions
6 {
7 static public Money as_money(this double amount)
8 {
9 var quotient = amount/0.01;
10 var wholePart = (int) quotient;
11 var mantissa = ((decimal) quotient) - wholePart;
12
13 var roundedAmount = mantissa >= .5m ? .01*(wholePart + 1) : .01*wholePart;
14 var cents = (roundedAmount*100).to_int();
15
16 return new Money(cents/100, cents%100);
17 }
18
19 static public Money as_money(this int amount)
20 {
21 var quotient = amount/0.01;
22 var wholePart = (int) quotient;
23 var mantissa = ((decimal) quotient) - wholePart;
24
25 var roundedAmount = mantissa >= .5m ? .01*(wholePart + 1) : .01*wholePart;
26 var cents = (roundedAmount*100).to_int();
27
28 return new Money(cents/100, cents%100);
29 }
30 }
31}