to-float

The to-float operation converts the input value into a floating-point number (decimal number). It is based on PHP’s type casting rules for floats.

How It Works

  • Integer → Float
    • Whole numbers are converted to their decimal equivalent.
    • Example: 42 → 42.0
  • String containing a number → Float
    • Numeric strings are converted to a float.
    • Example: “1.25” → 1.25
  • Boolean → Float
    • true converts to 1.0
    • false converts to 0.0
  • Null → Float
    • null converts to 0.0
  • Non-numeric strings → Float
    • If the string does not start with a digit, the result is 0.0.
    • Example: “abc123” → 0.0
    • If the string starts with digits, PHP attempts to parse them as a number.
    • Example: “123abc” → 123.0
  • Arrays or objects → Error
    • Arrays and objects cannot be converted into floats. Attempting to do so will cause an error.

Examples

InputResult
4242.0
“1.25”1.25
“123abc”123.0
“abc123”0.0
true1.0
false0.0
null0.0
[1,2,3]❌ Error
{ foo: “bar” }❌ Error

Usage in PalDock

Use to-float when:

  • An API requires numeric values in float format.
  • You need to ensure consistent numeric formatting before sending data.
  • A field may contain string numbers that should be interpreted as floats.

Note: Be cautious with mixed strings like “123abc”. They will partially convert, which may not always be the desired behavior. If you require strict numeric-only values, combine to-float with validation rules.

References

Insights that
helps you grow

  • Platform Pick 1: Win Stakeholder Support
    Feeling like your affiliate marketing channel needs a boost, or you don’t have one yet? You’re on the right track! The first step is getting…
  • How to: Defining Goals and Expectations
    Defining goals and expectations is a fundamental step in managing an affiliate program. Setting clear goals and understanding what you want to achieve through the…
  • How to: Motivating and Rewarding Partners
    Motivating and rewarding your affiliate partners is essential for their engagement, activity, and long-term collaboration. Proper motivation and rewards can encourage your partners to put…

Dominate Your Industry