JavaScript သင်္ချာအရာဝတ္ထု
JavaScript Math object သည် ဂဏန်းများပေါ်တွင် သင်္ချာဆိုင်ရာ လုပ်ဆောင်ချက်များကို လုပ်ဆောင်နိုင်စေပါသည်။
ဥပမာ
Math.PI;
သင်္ချာအရာဝတ္ထု
အခြားအရာဝတ္ထုများနှင့်မတူဘဲ သင်္ချာအရာဝတ္တုတွင် constructor မရှိပါ။
သင်္ချာအရာဝတ္ထုသည် တည်ငြိမ်သည်။
Math object တစ်ခုကို ဦးစွာ မဖန်တီးဘဲ method နှင့် properties အားလုံးကို သုံးနိုင်သည်။
သင်္ချာဂုဏ်သတ္တိများ (ကိန်းသေများ)
သင်္ချာပစ္စည်းတစ်ခုခုအတွက် syntax သည် : .Math.property
JavaScript သည် သင်္ချာဂုဏ်သတ္တိများအဖြစ် ဝင်ရောက်နိုင်သော သင်္ချာကိန်းသေ ၈ လုံးကို ပံ့ပိုးပေးသည်-
ဥပမာ
Math.E // returns Euler's number
Math.PI // returns PI
Math.SQRT2 // returns the square root of 2
Math.SQRT1_2 // returns the square root of 1/2
Math.LN2 // returns the natural logarithm of 2
Math.LN10 // returns the natural logarithm of 10
Math.LOG2E // returns base 2 logarithm of E
Math.LOG10E // returns base 10 logarithm of E
သင်္ချာနည်းများ
သင်္ချာအတွက် syntax သည် မည်သည့်နည်းလမ်းများဖြစ်သည် ။ Math.method(number)
ဂဏန်းမှ ကိန်းပြည့်
ဂဏန်းတစ်ခုကို ကိန်းပြည့်တစ်ခုသို့ ပတ်ရန် ဘုံနည်းလမ်း 4 ခုရှိသည်။
သင်္ချာဝိုင်း(x) | x သည် ၎င်း၏အနီးဆုံးကိန်းပြည့်သို့ အဝိုင်းသားပြန်ပေးသည်။ |
Math.ceil(x) | x သည် ၎င်း၏ အနီးဆုံးကိန်းပြည့်သို့ ဝိုင်းထားသည်။ |
Math.floor(x) | x သည် ၎င်း၏အနီးဆုံးကိန်းပြည့်သို့ အဝိုင်းချုံ့ထားသည်။ |
Math.trunc(x) | x ၏ ကိန်းပြည့်အပိုင်းကို ပြန်ပေးသည် ( ES6 တွင် အသစ် ) |
Math.round()
Math.round(x)
အနီးဆုံးကိန်းပြည့်ကို ပြန်ပေးသည်-
ဥပမာများ
Math.round(4.6);
Math.round(4.5);
Math.round(4.4);
Math.ceil()
Math.ceil(x)
အနီးဆုံးကိန်းပြည့်သို့ ဝိုင်း ထားသော x တန်ဖိုးကို ပြန်ပေးသည် -
ဥပမာ
Math.ceil(4.9);
Math.ceil(4.7);
Math.ceil(4.4);
Math.ceil(4.2);
Math.ceil(-4.2);
Math.floor()
Math.floor(x)
x ၏တန်ဖိုးကို ၎င်း၏အနီးဆုံးကိန်းပြည့်သို့ ပြန်ပေး သည်-
ဥပမာ
Math.floor(4.9);
Math.floor(4.7);
Math.floor(4.4);
Math.floor(4.2);
Math.floor(-4.2);
Math.trunc()
Math.trunc(x)
x ၏ ကိန်းပြည့်ကို ပြန်ပေးသည်-
ဥပမာ
Math.trunc(4.9);
Math.trunc(4.7);
Math.trunc(4.4);
Math.trunc(4.2);
Math.trunc(-4.2);
Math.sign()
Math.sign(x)
x သည် အနှုတ်၊ null သို့မဟုတ် positive ဖြစ်ပါက ပြန်ပေးသည်-
ဥပမာ
Math.sign(-4);
Math.sign(0);
Math.sign(4);
Math.trunc() နှင့် Math.sign() ကို JavaScript 2015 - ES6 တွင် ထည့်သွင်းခဲ့သည် ။
Math.pow()
Math.pow(x, y)
x တန်ဖိုးကို y ၏ ပါဝါသို့ ပြန်ပေးသည်-
ဥပမာ
Math.pow(8, 2);
Math.sqrt()
Math.sqrt(x)
x ၏ နှစ်ထပ်ကိန်းကို ပြန်ပေးသည်-
ဥပမာ
Math.sqrt(64);
Math.abs()
Math.abs(x)
x ၏ အကြွင်းမဲ့ (အပြုသဘော) တန်ဖိုးကို ပြန်ပေးသည်။
ဥပမာ
Math.abs(-4.7);
Math.sin()
Math.sin(x)
ထောင့် x (ရေဒီယံဖြင့်ပေးသည်) ၏ sine (-1 နှင့် 1 အကြားတန်ဖိုး) ကို ပြန်ပေးသည်။
အကယ်၍ သင်သည် radian အစား ဒီဂရီကို အသုံးပြုလိုပါက၊ သင်သည် ဒီဂရီကို radian သို့ ပြောင်းရပါမည်-
ရေဒီယံရှိ ထောင့် = ဒီဂရီ x PI / 180 ထောင့်။
ဥပမာ
Math.sin(90 * Math.PI / 180); // returns 1 (the sine of 90 degrees)
Math.cos()
Math.cos(x)
ထောင့် x (ရေဒီယံဖြင့်ပေးသည်) ၏ -1 နှင့် 1 ကြားတန်ဖိုးကို cosine ကို ပြန်ပေးသည်။
အကယ်၍ သင်သည် radian အစား ဒီဂရီကို အသုံးပြုလိုပါက၊ သင်သည် ဒီဂရီကို radian သို့ ပြောင်းရပါမည်-
ရေဒီယံရှိ ထောင့် = ဒီဂရီ x PI / 180 ထောင့်။
ဥပမာ
Math.cos(0 * Math.PI / 180); // returns 1 (the cos of 0 degrees)
Math.min() နှင့် Math.max()
Math.min()
ငြင်း ခုံ Math.max()
မှုများစာရင်းတွင် အနိမ့်ဆုံး သို့မဟုတ် အမြင့်ဆုံးတန်ဖိုးကို ရှာဖွေရန် အသုံးပြုနိုင်သည်။
ဥပမာ
Math.min(0, 150, 30, 20, -8, -200);
ဥပမာ
Math.max(0, 150, 30, 20, -8, -200);
Math.random()
Math.random()
0 (ပါဝင်) နှင့် 1 (သီးသန့်) အကြား ကျပန်းနံပါတ်ကို ပြန်ပေးသည်-
ဥပမာ
Math.random();
Math.random()
ဤသင်ခန်းစာ၏ နောက်အခန်းတွင် သင်အကြောင်းပိုမိုလေ့လာနိုင်ပါမည် ။
Math.log() နည်းလမ်း
Math.log(x)
x ၏ သဘာဝ လော့ဂရစ်သမ်ကို ပြန်ပေးသည်။
သဘာဝ လော့ဂရစ်သမ် သည် ကြီးထွားမှု အဆင့်သို့ ရောက်ရန် လိုအပ်သော အချိန်ကို ပြန်ပေးသည်-
ဥပမာများ
Math.log(1);
Math.log(2);
Math.log(3);
Math.E နှင့် Math.log() တို့သည် အမွှာများဖြစ်သည်။
10 ရဖို့ Math.E ကို ဘယ်နှစ်ခါမြှောက်ရမလဲ။
Math.log(10);
Math.log2() နည်းလမ်း
Math.log2(x)
x ၏ အခြေခံ 2 လော့ဂရစ်သမ်ကို ပြန်ပေးသည်။
8 ရဖို့ 2 ကို ဘယ်နှစ်ခါ မြှောက်ရမလဲ။
Math.log2(8);
Math.log10() နည်းလမ်း
Math.log10(x)
x ၏ အခြေခံ 10 လော့ဂရစ်သမ်ကို ပြန်ပေးသည်။
1000 ရဖို့ 10 ကို ဘယ်နှစ်ခါ မြှောက်ရမှာလဲ။
Math.log10(1000);
JavaScript သင်္ချာနည်းလမ်းများ
Method | Description |
---|---|
abs(x) | Returns the absolute value of x |
acos(x) | Returns the arccosine of x, in radians |
acosh(x) | Returns the hyperbolic arccosine of x |
asin(x) | Returns the arcsine of x, in radians |
asinh(x) | Returns the hyperbolic arcsine of x |
atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |
atan2(y, x) | Returns the arctangent of the quotient of its arguments |
atanh(x) | Returns the hyperbolic arctangent of x |
cbrt(x) | Returns the cubic root of x |
ceil(x) | Returns x, rounded upwards to the nearest integer |
cos(x) | Returns the cosine of x (x is in radians) |
cosh(x) | Returns the hyperbolic cosine of x |
exp(x) | Returns the value of Ex |
floor(x) | Returns x, rounded downwards to the nearest integer |
log(x) | Returns the natural logarithm (base E) of x |
max(x, y, z, ..., n) | Returns the number with the highest value |
min(x, y, z, ..., n) | Returns the number with the lowest value |
pow(x, y) | Returns the value of x to the power of y |
random() | Returns a random number between 0 and 1 |
round(x) | Rounds x to the nearest integer |
sign(x) | Returns if x is negative, null or positive (-1, 0, 1) |
sin(x) | Returns the sine of x (x is in radians) |
sinh(x) | Returns the hyperbolic sine of x |
sqrt(x) | Returns the square root of x |
tan(x) | Returns the tangent of an angle |
tanh(x) | Returns the hyperbolic tangent of a number |
trunc(x) | Returns the integer part of a number (x) |
သင်္ချာရည်ညွှန်းချက်အပြည့်အစုံ
ပြီးပြည့်စုံသော အကိုးအကားအတွက်၊ ကျွန်ုပ်တို့၏ ပြီးပြည့်စုံသော သင်္ချာဆိုင်ရာ အ ကိုးအကားသို့ သွားပါ ။
ကိုးကားချက်တွင် သင်္ချာဂုဏ်သတ္တိများနှင့် နည်းလမ်းအားလုံး၏ ဖော်ပြချက်များနှင့် ဥပမာများ ပါရှိသည်။