Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 30, 2020 02:19 pm GMT

Daily Challenge 276 - Unwanted Dollar Signs

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 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, write a simple function that converts a string representing a number into the number itself. Your function should be able to handle negatives!

Examples:

money_value("12.34") => 12.34
money_value("-0.89") => -0.89
money_value(" .11") => 0.11
money_value("007") => 7

Tests:
money_value("-$ 0.1")
money_value("12.34")
money_value("$-2.3456")
money_value("$.2")

Good luck!

This challenge comes from geoffp on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-276-unwanted-dollar-signs-458j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To