本文整理匯總了Java中java.lang.Math.round方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.round方法的具體用法?Java Math.round怎麽用?Java Math.round使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Math
的用法示例。
在下文中一共展示了Math.round方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clampValue
import java.lang.Math; //導入方法依賴的package包/類
public Object clampValue(Object value) {
if (value instanceof Float || value instanceof Integer) {
float val = (value instanceof Float)
? (Float)value : (Integer) value;
val = (val < min) ? min : (val > max) ? max : val;
if (value instanceof Float)
return (Float)val;
else
return (Integer)Math.round(val);
}
return value;
}
示例2: _doStateChangeV1
import java.lang.Math; //導入方法依賴的package包/類
void _doStateChangeV1(boolean force) {
//Log.v(TAG,"S "+_dPadStateH+" "+_dPadStateV);
// compile our state value
short s = _buttonStateV1; // buttons
s |= (_dPadStateH > 0 ? 1 : 0) << 5; // sign bit
s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateH)) * 15.0))) << 6; // mag
s |= (_dPadStateV > 0 ? 1 : 0) << 10; // sign bit
s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateV)) * 15.0))) << 11; // mag
// if our compiled state value hasn't changed, don't send.
// (analog joystick noise can send a bunch of redundant states through
// here)
// The exception is if forced is true, which is the case with packets
// that
// double as keepalives.
if ((s == _lastSentState) && (!force))
return;
_stateBirthTimes[_nextState] = SystemClock.uptimeMillis();
_stateLastSentTimes[_nextState] = 0;
if (debug) Log.v(TAG, "STORING NEXT STATE: " + _nextState);
_statesV1[_nextState] = s;
_nextState = (_nextState + 1) % 256;
_lastSentState = s;
// if we're pretty up to date as far as state acks, lets go ahead
// and send out this state immediately..
// (keeps us nice and responsive on low latency networks)
int unackedCount = (_nextState - _requestedState) & 0xFF; // upcast to
// get
// unsigned
if (unackedCount < 0) throw new AssertionError();
if (unackedCount < 3) {
_shipUnAckedStatesV1();
}
}
示例3: getCursorLength
import java.lang.Math; //導入方法依賴的package包/類
protected int getCursorLength() {
return Math.round(1 + fit * (getAxisLength()-1));
}
示例4: getCursorFromRatio
import java.lang.Math; //導入方法依賴的package包/類
protected int getCursorFromRatio(float ratio) {
return Math.round((getAxisLength()-getCursorLength()) * ratio);
}
示例5: getNearestZPlane
import java.lang.Math; //導入方法依賴的package包/類
/**
* Computes the z-coordinate of the closest axial plane to the emitter.
*
* The coordinate of the plane is an integer
*
* @param z The z-value of the emitter.
* @return The z-coordinate of the nearest computational plane.
*/
private Long getNearestZPlane(double z) {
long zDiscrete;
zDiscrete = Math.round(z / this.resPSFAxial);
return zDiscrete;
}