Here you can find the source of roundFloatToUnitInverse(final float graphValue, final float graphUnit)
Parameter | Description |
---|---|
graphValue | a parameter |
graphUnit | a parameter |
public static long roundFloatToUnitInverse(final float graphValue, final float graphUnit)
//package com.java2s; /******************************************************************************* * Copyright (C) 2005, 2016 Wolfgang Schramm and Contributors * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation version 2 of the License./* www . j av a2s . c o m*/ * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *******************************************************************************/ public class Main { /** * Round floating value to an inverse long value. * * @param graphValue * @param graphUnit * @return */ public static long roundFloatToUnitInverse(final float graphValue, final float graphUnit) { if (graphUnit < 1) { if (graphValue < 0) { final float value1 = graphValue / graphUnit; final float value2 = value1 - 0.5f; final long value3 = (long) (value2); return value3; } else { final float value1 = graphValue / graphUnit; final float value2 = value1 + 0.5f; final long value3 = (long) (value2); return value3; } } else { // graphUnit > 1 return (long) (graphValue * graphUnit); } } }