PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Pinterest

Implement string-based rounding without floats

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in string-based numeric processing, arbitrary-precision arithmetic concepts, precise rounding rules including deterministic tie-breaking, and handling of sign and decimal edge cases, and falls under the Coding & Algorithms domain.

  • easy
  • Pinterest
  • Coding & Algorithms
  • Machine Learning Engineer

Implement string-based rounding without floats

Company: Pinterest

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

### Coding You are not allowed to parse the input into a built-in floating type (to avoid overflow and precision issues). Work directly on strings. #### 1) Implement `round(s)` from scratch Given a string `s` representing a decimal number, return a string representing the value **rounded to the nearest integer**. - `s` may include an optional sign (`+`/`-`) and an optional decimal point. - Examples of tricky inputs you must handle: - `"-.2"` (equivalent to `-0.2`) - `"2."` (equivalent to `2.0`) - Very long integer parts that would overflow `float()` Clarify and implement a deterministic tie-breaking rule (e.g., exactly `.5` cases). #### 2) Round a numeric string `s` to a given precision `p` Given two strings: - `s`: a decimal number as a string - `p`: a positive decimal precision as a string Return `s` rounded to the nearest multiple of `p` (as a string). Examples: - `s = "12567"`, `p = "100"` → return `"12600"` - `s = "1234.678"`, `p = "0.1"` → return `"1234.7"` Assume `p` is a power of 10 (e.g., `1000`, `0.01`, `0.1`). Specify how you format the output (e.g., whether to keep trailing zeros).

Quick Answer: This question evaluates proficiency in string-based numeric processing, arbitrary-precision arithmetic concepts, precise rounding rules including deterministic tie-breaking, and handling of sign and decimal edge cases, and falls under the Coding & Algorithms domain.

Related Interview Questions

  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest
  • Sample a string by real-valued scores - Pinterest (hard)
  • Find First Prefix-Matching Word - Pinterest (medium)
Pinterest logo
Pinterest
Dec 15, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
6
0

Coding

You are not allowed to parse the input into a built-in floating type (to avoid overflow and precision issues). Work directly on strings.

1) Implement round(s) from scratch

Given a string s representing a decimal number, return a string representing the value rounded to the nearest integer.

  • s may include an optional sign ( + / - ) and an optional decimal point.
  • Examples of tricky inputs you must handle:
    • "-.2" (equivalent to -0.2 )
    • "2." (equivalent to 2.0 )
    • Very long integer parts that would overflow float()

Clarify and implement a deterministic tie-breaking rule (e.g., exactly .5 cases).

2) Round a numeric string s to a given precision p

Given two strings:

  • s : a decimal number as a string
  • p : a positive decimal precision as a string

Return s rounded to the nearest multiple of p (as a string).

Examples:

  • s = "12567" , p = "100" → return "12600"
  • s = "1234.678" , p = "0.1" → return "1234.7"

Assume p is a power of 10 (e.g., 1000, 0.01, 0.1). Specify how you format the output (e.g., whether to keep trailing zeros).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinterest•More Machine Learning Engineer•Pinterest Machine Learning Engineer•Pinterest Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.