var x = Math.floor("1000.01"); //floor automatically converts string to number
String.prototype.toHHMMSS = function () { var sec_num = parseInt(this, 10); // don't forget the second param var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; }
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; }
value = -5.5 Math.floor(value) // -6 Math.ceil(value) // -5 Math.round(value) // -5 Math.trunc(value) // -5 parseInt(value) // -5 value | 0 // -5 ~~value // -5 value >> 0 // -5 value >>> 0 // 4294967291 value - value % 1 // -5
value = 5.5 Math.floor(value) // 5 Math.ceil(value) // 6 Math.round(value) // 6 Math.trunc(value) // 5 parseInt(value) // 5 ~~value // 5 value | 0 // 5 value >> 0 // 5 value >>> 0 // 5 value - value % 1 // 5
value = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1 Math.floor(value) // -900719925474100 Math.ceil(value) // -900719925474099 Math.round(value) // -900719925474099 Math.trunc(value) // -900719925474099 parseInt(value) // -900719925474099 value | 0 // -858993459 ~~value // -858993459 value >> 0 // -858993459 value >>> 0 // 3435973837 value - value % 1 // -900719925474099
var intvalue = Math.floor( floatvalue ); var intvalue = Math.ceil( floatvalue ); var intvalue = Math.round( floatvalue ); // `Math.trunc` was added in ECMAScript 6 var intvalue = Math.trunc( floatvalue );
value = Number.MAX_SAFE_INTEGER/10 // 900719925474099.1 Math.floor(value) // 900719925474099 Math.ceil(value) // 900719925474100 Math.round(value) // 900719925474099 Math.trunc(value) // 900719925474099 parseInt(value) // 900719925474099 value | 0 // 858993459 ~~value // 858993459 value >> 0 // 858993459 value >>> 0 // 858993459 value - value % 1 // 900719925474099
var item = items[Math.floor(Math.random()*items.length)];
/** Creates a new set identical to the specified set. */ public ObjectSet (ObjectSet set) { this((int)Math.floor(set.capacity * set.loadFactor), set.loadFactor); stashSize = set.stashSize; System.arraycopy(set.keyTable, 0, keyTable, 0, set.keyTable.length); size = set.size; }
/** Creates a new set identical to the specified set. */ public IntSet (IntSet set) { this((int)Math.floor(set.capacity * set.loadFactor), set.loadFactor); stashSize = set.stashSize; System.arraycopy(set.keyTable, 0, keyTable, 0, set.keyTable.length); size = set.size; hasZeroValue = set.hasZeroValue; }
/** Creates a new set identical to the specified set. */ public IntSet (IntSet set) { this((int)Math.floor(set.capacity * set.loadFactor), set.loadFactor); stashSize = set.stashSize; System.arraycopy(set.keyTable, 0, keyTable, 0, set.keyTable.length); size = set.size; hasZeroValue = set.hasZeroValue; }
/** Creates a new set identical to the specified set. */ public ObjectSet (ObjectSet set) { this((int)Math.floor(set.capacity * set.loadFactor), set.loadFactor); stashSize = set.stashSize; System.arraycopy(set.keyTable, 0, keyTable, 0, set.keyTable.length); size = set.size; }
/** Creates a new map identical to the specified map. */ public IntIntMap (IntIntMap map) { this((int)Math.floor(map.capacity * map.loadFactor), map.loadFactor); stashSize = map.stashSize; System.arraycopy(map.keyTable, 0, keyTable, 0, map.keyTable.length); System.arraycopy(map.valueTable, 0, valueTable, 0, map.valueTable.length); size = map.size; zeroValue = map.zeroValue; hasZeroValue = map.hasZeroValue; }
/** Creates a new map identical to the specified map. */ public ObjectMap (ObjectMap<? extends K, ? extends V> map) { this((int)Math.floor(map.capacity * map.loadFactor), map.loadFactor); stashSize = map.stashSize; System.arraycopy(map.keyTable, 0, keyTable, 0, map.keyTable.length); System.arraycopy(map.valueTable, 0, valueTable, 0, map.valueTable.length); size = map.size; }
/** Creates a new map identical to the specified map. */ public LongMap (LongMap<? extends V> map) { this((int)Math.floor(map.capacity * map.loadFactor), map.loadFactor); stashSize = map.stashSize; System.arraycopy(map.keyTable, 0, keyTable, 0, map.keyTable.length); System.arraycopy(map.valueTable, 0, valueTable, 0, map.valueTable.length); size = map.size; zeroValue = map.zeroValue; hasZeroValue = map.hasZeroValue; }
/** Creates a new map identical to the specified map. */ public IdentityMap (IdentityMap map) { this((int)Math.floor(map.capacity * map.loadFactor), map.loadFactor); stashSize = map.stashSize; System.arraycopy(map.keyTable, 0, keyTable, 0, map.keyTable.length); System.arraycopy(map.valueTable, 0, valueTable, 0, map.valueTable.length); size = map.size; }
private static String doubleToString(double value) { if (Double.compare(value, Math.floor(value)) == 0 && !Double.isInfinite(value)) { return Integer.toString((int) value); } // remove trailing zeroes NumberFormat f = NumberFormat.getInstance(Locale.ROOT); f.setMaximumFractionDigits(4); f.setMinimumIntegerDigits(1); return f.format(value); }
private static void awaitEvent(BooleanSupplier condition, long timeToWait, String description) { long timeToSleep = 200; for (int i = 0 ; i < Math.floor(timeToWait / timeToSleep); i++) { if (condition.getAsBoolean()) { return; } try { Thread.sleep(timeToSleep); } catch (InterruptedException e) { throw new IllegalStateException("Interrupted while waiting for " + description, e); } } throw new IllegalStateException("Timed out waiting for " + description); }
function guid() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } document.getElementById('jsGenId').addEventListener('click', function() { document.getElementById('jsIdResult').value = guid(); })