❔ How would one convert string to int?
I have a string "1.65" for example which I would want to convert to a int with the value 1.65
13 Replies
That isn't an int
But you would use
T.Parse()
or better yet, T.TryParse()
where T
is the type you want to parse into
So in your case, some sort of a decimal type
double
, float
, decimal
, etcOo yeah no not a int indeed
But needed to no how to Parse with C#
Angius
REPL Result: Success
Console Output
Compile: 662.527ms | Execution: 49.124ms | React with ❌ to remove this embed.
Thanks!
if you want that double (or float if you want) to be int you can use Convert or Cast
Just a heads up, Convert and Cast may yield different results
You will lose the decimal part though
It'd be best to round it first, then cast to int
Yes, Convert will round it up, cast will round it down
That way you have control over whether to round it, floor it, or ceiling it
Its representive of a percentage, so the only thing I would maybe have to do is *100
arion
REPL Result: Success
Console Output
Compile: 723.563ms | Execution: 53.269ms | React with ❌ to remove this embed.
That might be the best
Hehe 69
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.