เมธอด MathF.Cos() ใน C# ส่งคืนโคไซน์ของค่า float ที่ระบุ (เป็นเรเดียน)
ไวยากรณ์
public static float Cos (float val);
พารามิเตอร์ val คือมุมในหน่วยเรเดียน
ตัวอย่าง
using System;
class Demo {
public static void Main(){
float val1 = 70f;
float res = (val1 * (MathF.PI)) / 180;
Console.WriteLine(MathF.Cos(res));
}
}ผลลัพธ์
0.34202
ตัวอย่างที่ 2
using System;
class Demo {
public static void Main(){
float val1 = 90f;
float res = (val1 * (MathF.PI)) / 180;
Console.WriteLine(MathF.Cos(res));
}
}ผลลัพธ์
-4.371139E-08