TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Garth Douglass
from: Michael Stapleton
date: 1996-09-02 03:32:00
subject: Re: Fixing decimal return

-=> Quoting Garth Douglass to All <=-

Hello Garth,

GD> I was wondering if there is any way to fix the amount of decimal
GD> places that a float returns.  For instance if it was a price
GD> being returned, to limit it to only 2 decimal places.

If you want to print a float or double with 2 digits after the
decimal point use %f.2, like this:

double val 12.34;
printf("Value: %f.2 Rounded %f.2\n", val, val + 0.005);

Beware!  It can be dangerous using float or double for money,
because of binary rounding errors.

Michael Stapleton of Graphic Bits.

 * AmyBW v2.10 *
... This tagline is encrypted
--- AdeptXBBS v1.07f (Registered)
* Origin: Mach One BBS (3:713/615)
SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 808 809 932 934
SEEN-BY: 712/515 713/111 317 601 611 615 618 700 826 888 914 714/906 800/1
@PATH: 713/888 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.