6 kyu

Unwanted dollars

696 of 2,131geoffp

Description:

If you're faced with an input box, like this:

                                           +--------------+
  Enter the price of the item, in dollars: |              |
                                           +--------------+

do you put the $ sign in, or not? Inevitably, some people will type a $ sign and others will leave it out. The instructions could be made clearer - but that won't help those annoying people who never read instructions anyway.

A better solution is to write code that can handle the input whether it includes a $ sign or not.

So, we need a simple function that converts a string representing a number (possibly with a $ sign in front of it) into the number itself.

Remember to consider negative numbers (the - sign may come either before or after the $ sign, if there is one), and any extraneous space characters (leading, trailing, or around the $ sign) that the users might put in. You do not need to handle input with trailing characters other than spaces (e.g. "1.2 3" or "1$"). If the given string does not represent a number, (either with or without a $ sign), return 0.0 .

Fundamentals

Similar Kata:

More By Author:

Check out these other kata created by geoffp

Stats:

CreatedJan 9, 2017
PublishedFeb 8, 2017
Warriors Trained4772
Total Skips867
Total Code Submissions13071
Total Times Completed2131
C++ Completions340
C Completions242
JavaScript Completions564
Python Completions696
Kotlin Completions185
CoffeeScript Completions9
Java Completions178
Total Stars69
% of votes with a positive feedback rating90% of 467
Total "Very Satisfied" Votes386
Total "Somewhat Satisfied" Votes65
Total "Not Satisfied" Votes15
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • geoffp Avatar
  • Javatlacati Avatar
  • tachyonlabs Avatar
  • hobovsky Avatar
Ad