Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Shift Decimal Place Function
00:00
5 left

Shift Decimal Place Function

EasyPython

Problem

People may need to format integer-based values with a decimal scale before displaying them. Given an integer and a signed shift amount, return the exact decimal representation created by moving the decimal point.

A positive places value moves the decimal point left. A negative value moves it right. The input integer is treated as a sequence of digits with an implicit decimal point immediately after the last digit. Return the result as a string so no floating-point precision is lost.

Formal Specification

Implement shift_decimal(number, places):

  1. number is an integer, potentially negative, with no fractional part.
  2. places is an integer. Positive values move the decimal point left, negative values move it right, and zero leaves the number unchanged.
  3. Preserve all digits and any zeros required by the shift.
  4. Include a decimal point only when the result has a fractional part.
  5. Preserve a leading negative sign when number is negative.

Constraints

  • -10^18 <= number <= 10^18
  • -100 <= places <= 100
  • number is an integer
  • The output must be exact and must not use floating-point arithmetic

Function Signature

def shift_decimal(number, places):
Interviewer

Your question is Shift Decimal Place Function. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.