How to get correct divided value?

I’m Trying to divide value but it’s give me output 0.

var value = Nat.div(17,100);
// => 0

I need output 0.17
how can i get this kind of output?

Division with natural numbers will always result in a whole number (i.e. 0, 1, 2, etc.).
You will have to convert the Nat into a Float first, then divide it by 100.

1 Like

Have you any example Nat To Float and Float To Nat?

Have a look at the documentation. You may have to chain multiple conversions if there is no direct conversion for your input/output type

I tried but not working give me output 0.


I need 0.17

You turn it into a float, divide, which gives you 0.17, then you go ahead and turn it back into a Nat. A nat cannot hold non-integer values, therefore it cuts the number down to 0. Stick with the float

1 Like