Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Convert float to long in iOS

$
0
0
I'm using Unity3D to develop a mobile game with cross-platform, i.e. Android and iOS. It's written in C#. One of the variable is calculated as following: long hp; int lv; hp = (long)Math.Pow(1.5f, lv); The code works well on PC and Android. but not on iOS. On iOS, even when `lv=0`, the value of hp will become something like `46071824188000017409`. float temp = Mathf.Pow(1.5f, lv); //returns 1 when lv=0 long temp2 = (long)temp; //returns 4607182418800017409 I tried to debug it with Xcode, the value of `Math.Pow(1.5f, lv)` has no problem, so the problem is long-conversion. I tried to use `System.Convert.ToInt64` and it appears the same. The problem exists on both iOS6 and iOS7. Anyone knows how to deal with this?

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>