Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Re: Decimals an...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 1072 of 1118
Post > Topic >>

Re: Decimals and numbers

by Joe <joe@[EMAIL PROTECTED] > Dec 24, 2007 at 11:42 AM

Jim Higgins wrote:
> On Sun, 23 Dec 2007 12:08:35 -0500, Joe <joe@[EMAIL PROTECTED]
> wrote:
> 
>> +,* and -.
>>
>>
>> var
>> price,total,tax: interger;
> 
> Correct the spelling of "integer"
> 
> Assuming price and tax are really meant to be integers, you need to
> define total as real or you'll be unable to lose precision.
> 
> An item with a PRICE of $4 at a TAX RATE of 6% will have a TOTAL COST
> of $4.24 due to the added TAX AMOUNT of $0.24.  Your variables that
> hold these assorted values must be data types that will hold the value
> without losing accuracy or precision.
> 
>> write('Price    :  ');readln(price);
>> write('Tax Rate :  ');readln(tax);
>>
>> total:= price * tax;
> 
> If a 6% tax (for example) is to be entered as "6" then the calculation
> is:
> 
> total := price + price*tax/100
> 
> If a 6% tax is to be entered as "0.06" then the calculation is:
> 
> total := price + price*tax
> 
>> write('Your total is : $', total);
> 
> OK, but if you want a decimal value formatted a bit better, try this:
> 
> writeln('Your total is : $',total:5:2)
> 
> See page 261 in the Programmer's Reference for details on syntax of
> the "write" (and "writeln) procedures for a technically accurate, but
> somewhat confusing description of how to format output.
> 
> Note that certain values of price and tax could produce totals with
> three or more significant figures after the decimal.  That's messy so
> you'll need to deal with that using the round() function or something
> similar.
> 
> After calculating the total above you might try...
> 
> 	total := round(total*100)/100
> 
> before writing the formatted total.  The line above will take the
> original total and round it off to two significant figures after the
> decimal.
Thanks Jim and Merry Christmas
 




 5 Posts in Topic:
Decimals and numbers
Joe <joe@[EMAIL PROTEC  2007-12-23 12:08:35 
Re: Decimals and numbers
winston19842005 <bjjly  2007-12-23 12:25:19 
Re: Decimals and numbers
Jim Higgins <invalid@[  2007-12-24 01:10:29 
Re: Decimals and numbers
Joe <joe@[EMAIL PROTEC  2007-12-24 11:42:08 
Re: Decimals and numbers
Dr J R Stockton <jrs@[  2007-12-24 21:37:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:36:08 CDT 2008.