#Strange return with simple porcentage calculus

21 messages · Page 1 of 1 (latest)

primal stone
#

Hello, good afternoon.

Why this calculus above is giving always 0?

value := (counter / total) * 100

In calculator this is going to be correct, and parentesis is told to divide first.

#

above the log output -> total, value, counter

ocean ledge
#

what is the type of counter and total?

primal stone
#

gopls think they are int

ocean ledge
#

so let's say total is 100 and counter is 99, what would you expect the result of int(99) / int(100) to be given that the result of this operation is itself an int?

primal stone
#

a float?

ocean ledge
#

is a float an int?

primal stone
#

but I got what you are trying to say me

ocean ledge
#

so how would you solve it?

primal stone
#

it becomes an int when I multiply per 100, correct?

#

var counter float
var total float

ocean ledge
#

it never becomes an int, it's always an int given that you are dividing 2 int

primal stone
#

understood

ocean ledge
primal stone
#

I was thinking go will coerce for me

#

I can coerce only the values in division

ocean ledge
#

could you spell it out? It's easy to get it wrong and I want to make sure you understand

primal stone
#

solved

ocean ledge
#

👍

primal stone
#

casting the ints in (float32(a) / float32(b))