I am doing an equation and the outcome is 45.454545454545454545.

I would like to get rid of the 45454545 after the decimal point. and have 45%

$final=5/11*100;

Dani AI

Generated

has a percentage value with repeating decimals; 's cast-to-integer suggestion will remove the fractional part, but that may not be what you want if you expect normal rounding or need formatting.

If the goal is to round to the nearest whole percent, use round(); to always drop the fraction use intval() or floor(); to control output formatting (decimals, thousands separators) use number_format() or sprintf()/printf(). Example patterns:

$value = 45.454545;        // computed percentage
echo round($value) . '%';
$value = 45.454545;
echo intval($value) . '%';  // truncates toward zero
$value = 45.454545;
echo number_format($value, 0) . '%';  // format with 0 decimals

Documentation: round() manual, intval() manual, floor() manual, number_format() manual, sprintf() manual.

A few practical notes: casting or intval() truncates (45.9 becomes 45); round() follows PHP rounding modes (see docs). Be aware of floating-point precision when doing exact math; for high-precision decimal work consider the BCMath extension (bcdiv() manual) or scale-aware arithmetic. If the output must include a percent sign, append it as shown or use printf("%.0f%%", $value) to avoid accidental format-string issues.

Recommendation: for display-only percentages that should be the nearest integer use round() plus a percent sign; use intval()/floor() only when truncation is specifically required.

you need to use the PHP int() function:

$final=5/11*100;
$integer = (int)$final;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.