All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.util.SafeFloatParser Maven / Gradle / Ivy

There is a newer version: 9.4.9.0
Show newest version
package org.jruby.util;

import java.math.BigDecimal;

/**
 * A safer way to parse float values
 * 

* Prevents brute force attacks using the famous Java bug. */ public final class SafeFloatParser extends SafeDecimalParser { /** * Safe way of parsing a Float value from a String * * @param s * The input String * @return the Float value */ public static Float valueOf(String s) { Float result = null; Double decimalValue = decimalValueOf(s); if (decimalValue != null) { result = Float.valueOf(decimalValue.floatValue()); } return result; } /** * Safe way of parsing a Float value from a String * * @param s * The input String * @return the Float value */ public static Float parseFloat(String s) { return valueOf(s); } /** * Safe way of getting the float value
* prevents BigDecimal from calling Float.parseFloat() * * @param number * @return the float value */ public static float floatValue(Number number) { return Float.valueOf((float)decimalValue(number)); } /** * Safe way of getting the float value
* Prevents BigDecimal from calling Float.parseFloat() * * @param bigDecimal * @return the float value */ public static float floatValue(BigDecimal bigDecimal) { return Float.valueOf((float)decimalValue(bigDecimal)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy