C
C#2y ago
Odin

❔ Truncate

how do I Truncate a float to an int, I tried this

public int maxGap = 4;


maxGap = 4 + decimal.Truncate(player.position.x/500);

public int maxGap = 4;


maxGap = 4 + decimal.Truncate(player.position.x/500);
and it says
Argument 1: cannot convert from 'float' to 'decimal' [Assembly-CSharp]
Argument 1: cannot convert from 'float' to 'decimal' [Assembly-CSharp]
I really need to know how to truncate now
4 Replies
JakenVeina
JakenVeina2y ago
var maxGap = 4 + Convert.ToInt32(player.position.x/500);
var maxGap = 4 + Convert.ToInt32(player.position.x/500);
actually
var maxGap = 4 + Convert.ToInt32(decimal.Truncate(player.position.x/500));
var maxGap = 4 + Convert.ToInt32(decimal.Truncate(player.position.x/500));
per docs Convert.ToInt32() rounds so, you'd have to truncate first better yet
var maxGap = 4 + decimal.ToInt32(player.position.x / 500);
var maxGap = 4 + decimal.ToInt32(player.position.x / 500);
Odin
OdinOP2y ago
Oh, converttoint, why didn’t I think of that
JakenVeina
JakenVeina2y ago
¯\_(ツ)_/¯ I believe you can also just cast yeah, you can and it does truncate as well
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server