Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10943

Re: float

Date 2011-10-17 21:25 +0100
From Leigh Johnston <leigh@i42.co.uk>
Newsgroups comp.lang.c++
Subject Re: float
References <fa3c19f8-c2ed-4d12-b18e-e40b574cdd31@g16g2000yqi.googlegroups.com> <c8e5a21a-c456-44b7-823c-5d6a7f3ea76d@g25g2000yqh.googlegroups.com> <9g3h6iFpouU3@mid.individual.net>
Message-ID <XIGdnUIx58bFEgHTnZ2dnUVZ8hCdnZ2d@giganews.com> (permalink)

Show all headers | View raw


On 17/10/2011 21:23, Ian Collins wrote:
> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>>> hi all ,
>>>
>>> #include "stdafx.h"
>>> #include<stdio.h>
>>> using namespace System;
>>>
>>> int main(array<System::String ^> ^args)
>>> {
>>> float d = 4 / 3 ;
>>> printf("%f",d);
>>> return 0;
>>>
>>> }
>>>
>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>>
>> Hi Ramtin
>> Besides what Dombo wrote you can use static_cast:
>> float d = static_cast<float>(4)/3;
>
> If the OP were using C++, wouldn't it be easier just to write
>
> float d = float(4) / 3;

No it would be easier to just write

float d = 4.0f / 3.0f;

/Leigh

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

float ramtin <tom.t.2090@gmail.com> - 2011-10-17 12:40 -0700
  Re: float Dombo <dombo@disposable.invalid> - 2011-10-17 21:47 +0200
  Re: float Thomas Boell <tboell@domain.invalid> - 2011-10-17 21:50 +0200
    Re: float Sjouke Burry <S@P.NL> - 2011-10-26 23:13 +0000
  Re: float Saeed Amrollahi <amrollahi.saeed@gmail.com> - 2011-10-17 13:05 -0700
    Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:23 +1300
      Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:25 +0100
        Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:31 +0100
          Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:33 +0100
          Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:35 +1300
            Re: float ramtin <tom.t.2090@gmail.com> - 2011-10-17 13:49 -0700
  Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:19 +1300
    Re: float "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-10-18 00:55 +0100
      Re: float SG <s.gesemann@gmail.com> - 2011-10-18 05:34 -0700
        Re: float Christopher <cpisz@austin.rr.com> - 2011-10-27 14:29 -0700
          Re: float Dombo <dombo@disposable.invalid> - 2011-10-28 18:14 +0200
  Re: float 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 21:06 -0700
    Re: float red floyd <no.spam.here@its.invalid> - 2011-10-28 22:14 -0700
      Re: float 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 23:27 -0700
        Re: float red floyd <no.spam.here@its.invalid> - 2011-10-29 08:24 -0700
          Re: float ptyxs <kerloch@gmail.com> - 2011-10-30 01:40 -0700
            Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-30 22:27 +1300

csiph-web