Thread: conversion error?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    57

    Question conversion error?

    Megatron says..........hoping not to bother anyone too much with his dumb questions...........

    why do i get a possible loss of data warning on this

    float overtime1 = base * 1.5;
    float overtime2 = base * 2.0;

    at this point in the program there are already values entered for base
    the warning also says "convrting double into float"
    but ive never ever even declared a double in my program

    these arent actually errors but the compiler issues a warning
    but ive been told never to ignore a warning any ways thanks for any help i recieve
    =@-OmegatronO-@=

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    1.5 and 2.0 are doubles. 1.5f and 2.0f are floats.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    A constant literal such as 1.4 or 2.5 are considered double by the compiler, you can either declare your overtime variables as double or cast the literals.
    float overtime1 = base * (float)1.5;
    or
    float overtime1 = base * 1.5f;

    -Prelude
    My best code is written with the delete key.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Floating point constants are by default doubles

    Try
    float overtime1 = base * 1.5f;

    The 'f' suffix to 1.5 should make it a float constant

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    thanks alot you dont even know how much i get that
    not no more though
    =@-OmegatronO-@=

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM