Go: Convert float to int

When converting a floating-point number to an int type, the fraction is discarded (truncation towards zero):

var f float64 = 1.9
n := int64(f) // 1
n = int64(-f) // -1

Warning: If the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent.

Comments