C
C#13mo 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
JakenVeina13mo 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
Odin13mo ago
Oh, converttoint, why didn’t I think of that
JakenVeina
JakenVeina13mo ago
¯\_(ツ)_/¯ I believe you can also just cast yeah, you can and it does truncate as well
Accord
Accord13mo 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
More Posts
❔ how could I make very nice looking apps in c#what could I use to make very visually appealing apps in c# i want things such as animations, round❔ Using .NET android workload with LinuxWhen trying to build the android project in https://github.com/StereoKit/StereoKit.Templates/tree/ma❔ How to modify aspnetcorehealthcheck to add devices programmatically.I have aspnetcorehealthcheck on a .net core app. Everything works fine. How would we go about and❔ Should procedural 2d maps be with structs or instantiated with 'new'?I am creating a game that can sometimes have a 1000x1000 interior grids in width and height. Exterio✅ public readonly bool Equals(...)? - SOLVEDI created struct for my needs of representing a phone number prefix and intellisense offered me a "p❔ How to display All the integers in a list concatenated with a stringHello! I was wondering if there was a possible way of cancatenating elements inside a list (that are❔ pick up and drop objects in top down perspective (unity 2d)I'm trying to make a top down game on unity and i want the player to be able to pick up one item at ❔ Need help trying to make 2D car move from above```cs // { if (Input.GetKeyDown(KeyCode.W) == true) { myRigidbody.velociEF Core: Keep Copy of Entity with old state when updatingHello, I am trying to update an entity and keep its previous state as a copy disconnected from the d❔ Part of me feels like I need to learn System.Linq; one day```cs float[] overlaps = new float[] { second.Left - first.Right, // left second.Right - fir