Reputation: 85
I have code like this in F#
let fun a b=
let mutable x1=float 0
<some stuff>
x1r<- -a/b
let main argv
let a=Int32.Parse(Console.ReadLine())
let b=Int32.Parse(Console.ReadLine())
fun a b
And i have problem with converting -a/b to float. I tried oldschool *1.0f, and few other tricks, but none of them worked. Is there any way to convert this like that, or do i have to write it another way?
Upvotes: 3
Views: 979
Reputation:
Your question is not very clear but it looks like to me that you are dividing two int
and expect that converting the result to a float
would keep the fractional part but, when you divide two int
s, you get back an int
and converting it to a float
cannot bring back the fractional part.
You should either convert both a
and b
to float
before performing the division (float -a) / (float b)
or, to begin with, read float
values from the console with Console.ReadLine() |> float
.
Upvotes: 4