C#-簡易重量換算

最近看到健身房的啞鈴重量單位為磅,自己比較習慣用公斤,所以寫了一個簡易的C#換算。

程式碼:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class WeightExchange : MonoBehaviour {
    public float KG;
    public float LBS;
    public Text Log;
	// Use this for initialization
	void Start () {
        Log.text = "Iron Grip啞鈴磅數公斤換算表\n";
        Onlog();
    }

	// Update is called once per frame
	void Update () {

	}

    public float Exchange(float lbs)
    {
        LBS = lbs;
        KG = LBS / 2.205f;

        return KG;
    }

    public void Onlog()
    {
        for (int i = 5; i <= 150; i+=5)
        {
            Log.text += i + "磅 = " + Exchange(i) + "公斤\n";
            Debug.Log(i + "磅 = " + Exchange(i) + "公斤");
        }

    }
}

輸出結果:
1.
weightexchange0

2.
weightexchange

發表留言