在OCaml中将float转换为int [英] Cast float to int in OCaml

查看:106
本文介绍了在OCaml中将float转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何在OCaml中将浮点数转换为整数?

How am I supposed to cast a float to an integer in OCaml?

我知道如何从int中获取浮点数,但是似乎没有一种简单的方法来从int中获取浮点数.

I know how to get a float from an int, but there doesn't seem to be an easy way to get an int from a float.

推荐答案

# int_of_float ;;
- : float -> int = <fun>

我假设您想要附近的int(与C一样,该值向0舍入).

I assume you want a nearby int (this rounds towards zero, same as C does).

如果要使用IEEE表示法,请参见Int64.bits_of_float.

If you want the IEEE representation, see Int64.bits_of_float.

这篇关于在OCaml中将float转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆