โ† Amazon questions

Float to string conversion

Filed under Amazon

Free read 1 of 3

Split the float into integer and fractional components.

The question

Convert a floating-point number to its string representation without using built-in conversion functions like str() or sprintf().

Constraints

  • Must handle negative numbers.
  • Must handle decimal points.
  • Precision requirements should be defined.

Examples

Input
123.45
Output
"123.45"
Why
Manual extraction of integer and fractional parts.

Approach

  1. Split the float into integer and fractional components.

Tips

  • What they are testing: Test with 0.0, negative numbers, and numbers with trailing zeros (e.g., 1.50).
  • Common mistake: Precision loss when multiplying the fractional part by powers of 10.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.