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 > C Moderated > Re: Working wit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 6 Topic 1081 of 1126
Post > Topic >>

Re: Working with Cash and uses of Typedef

by =?ISO-8859-1?Q?Hans-Bernhard_Br=F6ker?= <HBBroeker@[EMAIL PROTECTED] > Apr 18, 2008 at 04:11 PM

Philluminati wrote:
> I am writing a poker game which needs to work with cash. I am aware
> that there are problems with floats that make them unsuitable for
> storing money values. On top of this I may be expected to do
> operations such as £10.52 / 3. Which data type should I use instead?

Fixed-point.  Simply put you keep monetary amounts in cents/pennies, not 
Dollars/Pounds/Euros

> Further to this, is anyone away of legally what the obligations would
> be when the outcome is 3.566666667?

The meaning of "legal obligation" varies with the legal province (a.k.a. 
"country") you're in, and sometimes even with the particular profession. 
  E.g. shops are generally required to round to the nearest cent, 
whereas banks may be obliged to compute down to 1 percent of a penny 
(with "banker's rule" rounding to make it unbiased).

> And finally, why do I see people typedef values in C and, for example,
> use size_t rather than an int? Why is the type hidden like this?

Because size_t can be equivalent to a different type, depending on the 
platform and compiler settings.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 6 Posts in Topic:
Working with Cash and uses of Typedef
Philluminati <Phillip.  2008-04-16 16:57:04 
Re: Working with Cash and uses of Typedef
Carl Barron <cbarron41  2008-04-18 16:11:08 
Re: Working with Cash and uses of Typedef
Keith Thompson <kst-u@  2008-04-21 13:18:44 
Re: Working with Cash and uses of Typedef
=?ISO-8859-1?Q?Hans-Bernh  2008-04-18 16:11:16 
Re: Working with Cash and uses of Typedef
Thomas Richter <thor@[  2008-04-18 16:11:18 
Re: Working with Cash and uses of Typedef
Brian Inglis <Brian.In  2008-04-18 16:12:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Wed Jul 9 0:34:53 CDT 2008.