Computer Language/유니티

실수를 많이 해서 실수형.

알 수 없는 사용자 2014. 3. 31. 10:15

using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

float f1 = 0.1f - 0.2f;

float f2 = 43.1f - 43.2f;

double d3 = 0.1 - 0.2;

print("0.1-0.2=" + f1);

print ("43.1f-43.2f = " + f2);

if(f1 == f2)

{

print("Equal");

}

else{

print ("Not Equal");

}

}

// Update is called once per frame

void Update () {

}

}

실수형은 실수를 많이 한다.


using UnityEngine;

using System.Collections;


public class Chap3 : MonoBehaviour {


// Use this for initialization

void Start () {

decimal a = 0.1m - 0.2m;

decimal b = 43.1m - 43.2m;

print (" 0.1m - 0.2m = " + a);

print (" 43.1m - 43.2m = " + b);

if(a == b)

print ("equal");

else

print ("Not Equal");

}

// Update is called once per frame

void Update () {

}

}
decimal은 오차가 없다