Thanks everyone for their prompt reply.<br><br>What solution Beven suggested works pretty well when decimal place is 2 and i appreciate his early response .<br><br>How ever we have given option for clients to change decimal places to 2 3 4 5 6, Unfortunatly we forgot to mention to clients these options are for amounts how ever we made that tab generic for anything related to extended so can argue with them.<br>
<br>So for time being i did a work arround though it is not at an ideal solution<br><br>when he enter say 123.345678<br><br>then i took the decimal place<br><br>ipos:= pos('.',temp);<br>value := strtofloat(copy(temp,1,ipos+decimalpace))<br>
<br>this works out for time being as a work arround since my clint cant wait any long.<br><br>However thanks John for the way u told will look in to it.<br><br>thanks<br><br><div class="gmail_quote">On Wed, Mar 3, 2010 at 3:42 PM, John Bird <span dir="ltr"><<a href="mailto:johnkbird@paradise.net.nz">johnkbird@paradise.net.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Tax calculations are tricky, as there are rules about either truncating to<br>
whole dollars or down to whole cents. These are not maths functions, you<br>
may have to make your own.<br>
<br>
I have seen people do all sorts of tricks with formating floats as strings<br>
and truncating, and converting back but to my mind the best is to calculate<br>
in cents - which is what the rules are actually specifying. ie convert the<br>
dollars to integer or int64 cents, do the calculation and convert the result<br>
back to float. Otherwise you start getting oddities where Net + GST <><br>
Gross when the amounts are printed to dollars and cents.<br>
<br>
Here is an example with GST calculations - guaranteeing that Net + GST =<br>
Gross when printed as dollars and cents to 2 decimal places..:<br>
<br>
//IRD guidelines are that GST calculated amount is rounded down to nearest<br>
cent<br>
procedure xcGSTCalc(aGSTRatePercent:double;var aNetVal:Double;var<br>
aGSTVal:Double;var aInclVal:Double);<br>
var<br>
lGSTRate:int64; //gst rate as cents per 100 dollars (ie per 10000<br>
cents)=GSTRate*100<br>
lNetCents,lGSTCents,lInclCents:int64;<br>
begin<br>
lGSTRate:=trunc(aGSTRatePercent*100); //eg 1250<br>
lNetCents:=round(aNetVal*100);<br>
lGSTCents:=(lNetCents * lGSTRate) div 10000; //1250 div 10000 = .125<br>
//note integer division<br>
truncates fractions<br>
lInclCents:=lNetCents+lGSTCents;<br>
//return to float - this should guarantee nothing after first 2 decimal<br>
places<br>
aNetVal:=lNetCents/100;<br>
aGSTVal:=lGSTCents/100;<br>
aInclVal:=lInclCents/100;<br>
end;<br>
<br>
similar rules apply to with tax calculations - there is usually some<br>
truncating to whole dollars or cents involved.<br>
<br>
Incidentally this stuff fools the IRD too - for years the printed tax tables<br>
have had some errors because they didn't follow their own truncating and<br>
rounding rules for some calculations - and the printed tax tables did not<br>
agree with their online tax calculator which was correct.<br>
<font color="#888888"><br>
John<br>
</font><div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> vikas<br>