Float not returning decimal when dividing

th3ramr0d

I am dividing 2 numbers and want to return a decimal when appropriate. But it is returning whole number on everything.

float temp = (twoMileInSeconds - 774) / 6;
timeIndex = (int)Math.floor(temp);

debug1.setText("Before rounding: " + temp);
debug2.setText("After rounding: " + timeindex);

Thanks

Nerdy Bunz

What data type is 'twomileinsecods' ? If its int, then that is the problem... or maybe if you put 6.0 instead of 6.

To ensure that the division taking place to the right of the equals sign results in a float, make sure all data types on the right are already floats. The problem is that it's casting to float AFTER the division has already taken place.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

trouble getting correct answer when dividing by a decimal

From Dev

Get the quotient when dividing a float in Python 2.7

From Dev

Why does Firebird truncate decimal places when dividing?

From Dev

getting integer result when dividing float by integer in c

From Dev

Python: dividing a float by a variable

From Dev

django float or decimal are rounded unintentionally when saving

From Dev

django float or decimal are rounded unintentionally when saving

From Dev

Dividing float point data in bash

From Dev

Dividing float by int and storing as float - Division by zero

From Dev

Why does dividing a int with a float result in a float?

From Dev

How to make sqlalchemy return float instead of Decimal when reflecting tables?

From Dev

Parsing a long/double/float number when forcing decimal separator

From Dev

Dividing float by double vs dividing double by double in java

From Dev

snprintf is returning a string containing a question mark when using a float

From Dev

MySQL Decimal not returning results

From Dev

Returning SQL as decimal

From Dev

Pyodbc returning (Decimal('100.00'),)

From Dev

Python float decimal places

From Dev

Format decimal in float

From Dev

Remainder When Dividing Large Number

From Dev

Float is not returning correct value

From Dev

decimal.Decimal(float) vs. decimal.Decimal.from_float(float)

From Dev

dividing a decimal type in SQL Server results in unnecessary trailing zeros

From Dev

Dividing two integers doesn't print as a decimal number in Rust

From Dev

PHP dividing decimal/integer values gives round up output

From Dev

Function Returning Whole Number, not Decimal

From Dev

Why isn't 'f' necessary when declaring a non-decimal float in Java?

From Dev

How do I check the default decimal precision when converting float to str?

From Dev

When printing a float, how can you print decimal places more precisely?

Related Related

  1. 1

    trouble getting correct answer when dividing by a decimal

  2. 2

    Get the quotient when dividing a float in Python 2.7

  3. 3

    Why does Firebird truncate decimal places when dividing?

  4. 4

    getting integer result when dividing float by integer in c

  5. 5

    Python: dividing a float by a variable

  6. 6

    django float or decimal are rounded unintentionally when saving

  7. 7

    django float or decimal are rounded unintentionally when saving

  8. 8

    Dividing float point data in bash

  9. 9

    Dividing float by int and storing as float - Division by zero

  10. 10

    Why does dividing a int with a float result in a float?

  11. 11

    How to make sqlalchemy return float instead of Decimal when reflecting tables?

  12. 12

    Parsing a long/double/float number when forcing decimal separator

  13. 13

    Dividing float by double vs dividing double by double in java

  14. 14

    snprintf is returning a string containing a question mark when using a float

  15. 15

    MySQL Decimal not returning results

  16. 16

    Returning SQL as decimal

  17. 17

    Pyodbc returning (Decimal('100.00'),)

  18. 18

    Python float decimal places

  19. 19

    Format decimal in float

  20. 20

    Remainder When Dividing Large Number

  21. 21

    Float is not returning correct value

  22. 22

    decimal.Decimal(float) vs. decimal.Decimal.from_float(float)

  23. 23

    dividing a decimal type in SQL Server results in unnecessary trailing zeros

  24. 24

    Dividing two integers doesn't print as a decimal number in Rust

  25. 25

    PHP dividing decimal/integer values gives round up output

  26. 26

    Function Returning Whole Number, not Decimal

  27. 27

    Why isn't 'f' necessary when declaring a non-decimal float in Java?

  28. 28

    How do I check the default decimal precision when converting float to str?

  29. 29

    When printing a float, how can you print decimal places more precisely?

HotTag

Archive