Unwanted dollars
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 .
Similar Kata:
Stats:
Created | Jan 9, 2017 |
Published | Feb 8, 2017 |
Warriors Trained | 4772 |
Total Skips | 867 |
Total Code Submissions | 13071 |
Total Times Completed | 2131 |
C++ Completions | 340 |
C Completions | 242 |
JavaScript Completions | 564 |
Python Completions | 696 |
Kotlin Completions | 185 |
CoffeeScript Completions | 9 |
Java Completions | 178 |
Total Stars | 69 |
% of votes with a positive feedback rating | 90% of 467 |
Total "Very Satisfied" Votes | 386 |
Total "Somewhat Satisfied" Votes | 65 |
Total "Not Satisfied" Votes | 15 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |