Class NumberCaster

java.lang.Object
ortus.boxlang.runtime.dynamic.casters.NumberCaster
All Implemented Interfaces:
IBoxCaster

public class NumberCaster extends Object implements IBoxCaster
I handle casting anything to a Number, but I will use the "smallest" number type possible So Integer, Long, Double, BigDecimal
  • Field Details

    • booleansAreNumbers

      public static boolean booleansAreNumbers
      If true, booleans will be treated as numbers, with true=1 and false=0 This is here for compat to toggle
  • Constructor Details

    • NumberCaster

      public NumberCaster()
  • Method Details

    • attempt

      public static CastAttempt<Number> attempt(Object object, boolean castDates)
      Tests to see if the value can be cast to a Number. Returns a CastAttempt<T> which will contain the result if casting was was successfull, or can be interogated to proceed otherwise.
      Parameters:
      object - The value to cast to a Number
      Returns:
      The Number value
    • attempt

      public static CastAttempt<Number> attempt(Object object)
      Tests to see if the value can be cast to a Number. Returns a CastAttempt<T> which will contain the result if casting was was successfull, or can be interogated to proceed otherwise.
      Parameters:
      object - The value to cast to a Number
      Returns:
      The Number value
    • cast

      public static Number cast(Object object)
      Used to cast anything to a Number, throwing exception if we fail
      Parameters:
      object - The value to cast to a Number
      Returns:
      The Number value
    • cast

      public static Number cast(boolean castDates, Object object)
      Used to cast anything to a Number, throwing exception if we fail
      Parameters:
      object - The value to cast to a Number
      Returns:
      The Number value
    • cast

      public static Number cast(Object object, Boolean fail)
      Used to cast anything to a Number
      Parameters:
      object - The value to cast to a Number
      fail - If true, throw exception if we fail
      Returns:
      The Number value
    • cast

      public static Number cast(Object object, Boolean fail, boolean castDates)
      Used to cast anything to a Number
      Parameters:
      object - The value to cast to a Number
      fail - If true, throw exception if we fail
      Returns:
      The Number value