https://codingrakitan.blogspot.com/2021/08/function-merubah-angka-biasa-menjadi.html Berikut adalah function untuk merubah angka bisa menjadi angka romawi pada bahasa pemrograman PHP. function numberToRomanRepresentation($number) { $map = array(‘M’ => 1000, ‘CM’ => 900, ‘D’ => 500, ‘CD’ => 400, ‘C’ => 100, ‘XC’ => 90, ‘L’ => 50, ‘XL’ => 40, ‘X’ => 10, ‘IX’ => 9, ‘V’ => 5, ‘IV’ => […]
Tag Archives: Angka
https://codingrakitan.blogspot.com/2021/08/merubah-angka-menjadi-nama-bulan-di-php.html Dengan menggunakan function anda dapat merubah bulan yang sebelumnya berbentuk angka menjadi nama bulan misalnya angka 1 menjadi Januari, 2 menjadi Februari, dan seterusnya.Berikut function yang dapat anda gunakan : function getBulan($bln){ switch ($bln){ case 1: return “Januari”; break; case 2: return “Februari”; break; case 3: return “Maret”; break; case 4: return “April”; break; […]
Contoh: Konversi Tanggal ke Angka // program to convert date to number // create date const d1 = new Date(); console.log(d1); // converting to number const result = d1.getTime(); console.log(result); Keluaran Mon Nov 09 2020 10:52:32 GMT+0545 (Nepal Time) 1604898452084 Dalam contoh di atas, new Date() konstruktor digunakan untuk membuat objek tanggal. Itu new Date() […]
Contoh 1: Menggunakan Number.isInteger() // program to check if a number is a float or integer value function checkNumber(x) { // check if the passed value is a number if(typeof x == ‘number’ && !isNaN(x)){ // check if it is integer if (Number.isInteger(x)) { console.log(`${x} is integer.`); } else { console.log(`${x} is a float value.`); […]
Contoh: Hasilkan Rentang Karakter // program to generate range of numbers and characters function* iterate(a, b) { for (let i = a; i <= b; i += 1) { yield i } } function range(a, b) { if(typeof a === ‘string’) { let result = […iterate(a.charCodeAt(), b.charCodeAt())].map(n => String.fromCharCode(n)); console.log(result); } else { let result […]
Jika Anda ingin menemukan bilangan bulat acak di antaranya min (termasuk) untuk maksimal (inklusif), Anda dapat menggunakan rumus berikut: Math.floor(Math.random() * (max – min + 1)) + min Contoh: Nilai Bilangan Bulat Antara Dua Angka // input from the user const min = parseInt(prompt(“Enter a min value: “)); const max = parseInt(prompt(“Enter a max value: […]
Contoh 1: Memformat Angka sebagai String Mata Uang // program to format numbers as currency string const formatter = new Intl.NumberFormat(‘en-US’, { style: ‘currency’, currency: ‘USD’ }); formatter.format(2500); Keluaran $2,500.00 Dalam program di atas, kami telah menggunakan Intl.NumberFormat obyek. Itu Intl.NumberFormat objek memungkinkan pemformatan angka peka bahasa. Contoh 2: Memformat Angka sebagai String Mata Uang […]
Contoh: Program untuk Menebak Angka // program where the user has to guess a number generated by a program function guessNumber() { // generating a random integer from 1 to 10 const random = Math.floor(Math.random() * 10) + 1; // take input from the user let number = parseInt(prompt(‘Guess a number from 1 to 10: […]
Contoh: Periksa Digit Terakhir /* program to check whether the last digit of three numbers is same */ // take input const a = prompt(‘Enter a first integer: ‘); const b = prompt(‘Enter a second integer: ‘); const c = prompt(‘Enter a third integer: ‘); // find the last digit const result1 = a % […]
Faktorial sebuah bilangan adalah hasil kali dari semua bilangan asal 1 ke nomor itu. Sebagai contoh, faktorial dari 5 adalah sama dengan 1 * 2 * 3 * 4 * 5 = 120. Faktorial bilangan positif n diberikan oleh: factorial of n (n!) = 1 * 2 * 3 * 4…..n Faktorial bilangan negatif tidak […]