Article View: alt.comp.lang.learn.c-c++
Article #65Re: Floating point equal to Integer Value ?
From: jan
Date: Tue, 10 Jul 2001 10:15
Date: Tue, 10 Jul 2001 10:15
45 lines
2482 bytes
2482 bytes
Where's the problem?
You have a redefinition int x and float x, which doesn't work
You can just compare with:
int x = 20;
float y =20.0;
if(x==y)
printf("Equal!");
else
printf ("Not equal!");
That's all. You can also cast (converting diffrent types):
y = (float)x;
"Alya Al Omrani" <alomrani@emirates.net.ae> schrieb im Newsbeitrag
news:9iejot$4an2@news.emirates.net.ae...
> Hi, how can i check if a floating point value is equal to integer value ?
> I tried looking of there is a function that does so but there isn't
>
> I tried doing the following
>
> /* lets say those are my values */
> int x=20;
> float x=20.0, z;
>
> z=(float)x;
> /* I used a printf staetment to check that the value of x was assigned to
z
> and it worked ! */
> printf("%f", z);
>
> /* here i want to check */
> if(z==x) /* at this instant it freezes */
> printf("values are equal");
> else
> printf("they r not euqal");
> ///////////////
>
>
> I sthere a substitue method that i can do so, i tried taking the % modulus
> of both z and x to see if it will give zero but i got same erro, the
program
> wont compile
>
>
>
Technical Details
Message-ID:
<9iekjv$pl5@parzival.khe.siemens.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!195.27.83.146!news-FFM2.ecrc.net!parzival.r30x.khe.scn.de!not-for-mailReferences:
<9iejot$4an2@news.emirates.net.ae>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,dbd8a1f951d6b446 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 108b44,dbd8a1f951d6b446 X-Google-Attributes: gid108b44,public X-Google-Thread: 10b1c0,dbd8a1f951d6b446 X-Google-Attributes: gid10b1c0,public X-Google-Thread: 109fba,dbd8a1f951d6b446 X-Google-Attributes: gid109fba,public X-Google-Thread: 108717,dbd8a1f951d6b446 X-Google-Attributes: gid108717,public X-Google-Thread: 114592,dbd8a1f951d6b446 X-Google-Attributes: gid114592,public X-Google-ArrivalTime: 2001-07-10 03:29:24 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!195.27.83.146!news-FFM2.ecrc.net!parzival.r30x.khe.scn.de!not-for-mail From: "jan" <1@2> Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++,comp.programming,comp.sys.lang.c++,csugrad.programming.c Subject: Re: Floating point equal to Integer Value ? Date: Tue, 10 Jul 2001 12:15:33 +0200 Organization: Siemens AG Lines: 47 Message-ID: <9iekjv$pl5@parzival.khe.siemens.de> References: <9iejot$4an2@news.emirates.net.ae> NNTP-Posting-Host: kh15110d2.khe.siemens.de X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200