Content · Programming · PHP

PHP doubleval() Function: Usage and Examples

Learn how PHP doubleval works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Converts a value to float; it is an alias of floatval().

What Is doubleval() in PHP?

Converts a value to float; it is an alias of floatval().

Its syntax is:

doubleval(mixed $value): float

Parameters:

  • $value — Accepted as mixed; required argument.

Return type: float. Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Availability: Core PHP.

Example 1: Basic Usage

<?php

var_dump(doubleval("12.5"));

Output:

float(12.5)

Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Example 2: A Different Input

<?php

var_dump(doubleval(8));

Output:

float(8)

Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Practical Example: Applying It in a Program

<?php

$values = ["2.25", "3.5"]; $total = 0.0; foreach ($values as $value) { $total += doubleval($value); } echo $total;

Output:

5.75

Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Important Behavior and Edge Cases

  • Key behavior: Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
doubleval()Converts a value to float; it is an alias of floatval().
floatval()floatval() and doubleval() are aliases; both convert values to floating-point numbers.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Converting a malformed numeric string may yield 0 or a partial numeric valueConverting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Key Takeaways

  • Converts a value to float; it is an alias of floatval().
  • Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.
  • Core PHP.

Summary: Converting a malformed numeric string may yield 0 or a partial numeric value. Validate external input.

Share this resourceSend this page to someone who may find it useful.