| Author |
Topic |
|
mark1504
Posting Yak Master
103 Posts |
Posted - 2005-09-19 : 08:03:32
|
| I need to return a figure to round pennies.Here's the relevant part of my SP:@InvTax Money=0,@Price Money=60.27@TaxRate Money=0.175SET @InvTax=@Price*@TaxRateI want @InvTax to be 10.5400, not 10.5473what do I need to do?ThanksMark |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-19 : 08:39:57
|
| Cant you do this in your Presentation layer?Try thisDeclare @InvTax MoneyDeclare @Price MoneyDeclare @TaxRate Moneyset @InvTax =0set @Price =60.27set @TaxRate =0.175SET @InvTax=@Price*@TaxRateselect convert(decimal(12,2),@invTax)MadhivananFailing to plan is Planning to fail |
 |
|
|
mark1504
Posting Yak Master
103 Posts |
Posted - 2005-09-19 : 09:55:27
|
| >>Cant you do this in your Presentation layer?No. This proc (in the complete version) gathers data from tables and writes to the invoices tables.>>select convert(decimal(12,2),@invTax)Many thanks. That seems fine for the purpose. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-09-19 : 10:55:17
|
You could use the ROUND function:select @InvTax=convert(decimal(10,2),round(@Price*@TaxRate,2)) Edit: fixed codeCODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-19 : 11:00:13
|
| MVJ, did you mean this?select @InvTax=convert(decimal(10,2),round(@Price*@TaxRate,2))MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-19 : 13:44:36
|
I agree; its not a Presentation Layer issue - the Tax Man will have a fit if his calculations are not done as per His Rules.So that must make it a Business Rule, right? - in which case you need a User Defined Function called RoundAndPutPennyFractionsInSwissBanklAccount() Note that ROUND() can take a third parameter to indicate whether "rounding" or "truncation" is to be performed. Also worth consider how Credit notes might behave - if you are storing them as Negative Amounts.Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-20 : 01:11:37
|
>>RoundAndPutPennyFractionsInSwissBanklAccount()Good Naming convention MadhivananFailing to plan is Planning to fail |
 |
|
|
mark1504
Posting Yak Master
103 Posts |
Posted - 2005-09-22 : 07:11:21
|
| >> select @InvTax=convert(decimal(10,2),round(@Price*@TaxRate,2))Isn't that belt and braces?The UDF sounds fine in theory but from my experience the VAT man doesn't care much for fractions of pennies anyway (depending on your particular trade.) Alas, if he thought there was much to make from it he would change the rules. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-22 : 08:54:33
|
"Isn't that belt and braces?"Which bit?Personally I would want the ROUND in there (I would then be sure of the behaviour of ROUND() [and even explicitly state ROUND or TRUNCATE if necessary]).The CONVERT(decimal(10,2) does nothing for me and I wouldn't want to rely on the default behaviour of the implicit conversion to money in:select @InvTax=@Price*@TaxRateif nothing else because [I think] that would be 4 d.p.Kristen |
 |
|
|
|