Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to change an enlarged floating point number into an integer int in C instead of inheriting the precision of float after forced conversion?
How to change an enlarged floating point number into an integer int in C instead of inheriting the precision of float after forced conversion?
First of all, it is correct to run your program with VC6.

The precision of float floating point number can be guaranteed within 6 decimal places, so your problem is not the precision of float, because you don't know what your wrong result is and you can't guess it.

The following is a program that uses arrays and loops, which saves code and adds two kinds of security processing: double precision and security operation (this also applies to your program, you can modify it).

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

int? Master ()

{

Double? x; //Double precision

int? Y, me;

int? a[ 13]={ 10000,5000,2000, 1000,50,20, 10,5,2, 1 };

int? b[ 13];

scanf("%lf ",& ampx);

x=? x * 100.0;

y =(int)x; //Safety calculation

For what? (I = 0; I< 13; i++)

{

b[i]? =? y/a[I];

y? =? y % a[I]; //y? -? a[i]*b[i]

}

For what? (I = 0; I< 13; i++)

{

if(b[i]==0)? Continue;

if(a[I]& lt; 10)// min

printf("%d? Finn:? %d\n ",a[i],b[I]);

Or what? if(a[I]& lt; 100)// coke

printf("%d? Jiao:? %d\n ",a[i]/ 10,b[I]);

Or what? //yuan

printf("%d? Yuan:? %d\n ",a[i]/ 100,b[I]);

}

System ("suspended");

Return? 0;

}