Here you can find the source of toRoman( ()
assert = require("assert"); Number.prototype.toRoman = (function () { var nmap = {//from ww w . j a v a 2s . c o m M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1 }; var toRomanR = function toRomanR(num) { for (var a in nmap) { if (nmap[a] <= num) { return a + toRomanR(num - nmap[a]); } } return ''; } return function toRoman() { return toRomanR(this); }; }()); assert.equal(Number(0).toRoman(),""); assert.equal(Number(1).toRoman(),"I"); assert.equal(Number(20).toRoman(),"XX"); assert.equal(Number(34).toRoman(),"XXXIV"); assert.equal(Number(99).toRoman(),"XCIX"); assert.equal(Number(999).toRoman(),"CMXCIX"); assert.equal(Number(2000).toRoman(),"MM"); assert.equal(Number(2999).toRoman(),"MMCMXCIX"); assert.equal(Number(12000).toRoman(),"MMMMMMMMMMMM");
Number.prototype.toRadians = function() { return this * Math.PI / 180;
function getHaversineDistance(point1, point2){ var R = 6372.8; var dLat = (point2.lat - point1.lat).toRadians(); var dLon = (point2.lon - point1.lon).toRadians(); var lat1 = point1.lat.toRadians(); var lat2 = point2.lat.toRadians(); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2) var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) return = R * c; ...
'use strict' Number.prototype.toRadians = function() { return this * Math.PI / 180;
Number.prototype.toRadians = function() { return (this.valueOf() * Math.PI) / 180;
function toReadableFileSize(bytes) { var i = 0; var byteUnits = [' bytes' , ' kB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']; while (bytes > 1024) { bytes = bytes / 1024; i++; if (i > 0) return bytes.toFixed(1) + byteUnits[i]; ...
$(document) function() { Number.prototype.toRoman= function () { var num = Math.floor(this), val, s= '', i= 0, v = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], r = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; function toBigRoman(n) { var ret = '', n1 = '', rem = n; while (rem > 1000) { ...
Number.prototype.toRoman= function () { var num = Math.floor(this), val, s= '', i= 0, v = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], r = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; function toBigRoman(n) { var ret = '', n1 = '', rem = n; while (rem > 1000) { var prefix = '', suffix = '', n = rem, s = '' + rem, magnitude = 1; ...
Number.prototype.degToRad = function () { return this.valueOf() / 180 * Math.PI;
Number.prototype.inRadians = function() { return this * Math.PI / 180.0;