java.lang.Math.floor()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中java.lang.Math.floor()方法的一些代码示例,展示了Math.floor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.floor()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:floor

Math.floor介绍

[英]Returns the double conversion of the most positive (closest to positive infinity) integer value less than or equal to the argument.

Special cases:

  • floor(+0.0) = +0.0
  • floor(-0.0) = -0.0
  • floor(+infinity) = +infinity
  • floor(-infinity) = -infinity
  • floor(NaN) = NaN
    [中]返回小于或等于参数的最大正(最接近正无穷大)整数值的双重转换。
    特殊情况:
    *地板(+0.0)=+0.0
    *地板(-0.0)=-0.0
    *楼层(+无限)=+无限
    *楼层(-无穷大)=-无穷大
    *楼层(南)=南

代码示例

代码示例来源:origin: stackoverflow.com

var x = Math.floor("1000.01"); //floor automatically converts string to number

代码示例来源:origin: stackoverflow.com

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;
}

代码示例来源:origin: stackoverflow.com

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;
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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 );

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

var item = items[Math.floor(Math.random()*items.length)];

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: libgdx/libgdx

/** 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;
}

代码示例来源:origin: skylot/jadx

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);
}

代码示例来源:origin: spring-projects/spring-framework

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);
}

代码示例来源:origin: stackoverflow.com

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();
})

相关文章