dollars

Version, currently master branch1 version
  • master branchlatestApr 22, 2017

github.com/kimburgess/dollar-conversion

Simple coding challenge and an excuse to play around with Crystal Lang!

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  dollars:
    github: kimburgess/dollar-conversion
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.20.5
License
MIT
Author
Kim Burgess
Target
  • dollars from src/dollars.cr

Dependencies

Runtime Dependencies

  • cli*github: mosop/cli

README

Data manipulation / coding challenge that a friend was given for an interview question. Thought it would be fun to attempt to implement and a good excuse to take a new language (Crystal) for a spin.

Build Status

Original brief and requirements:

Write a function (dollars) that accepts a String and returns a String. It will accept a numeric value as input, representing an amount of money, and the function will convert that value to its how it is written in English. Use any preferred programming language. For example, the input "1.11" will result in a return value of "one dollar and eleven cents"

Invalid characters should be ignored, meaning that every input string has an output string. The empty string produces "zero dollars and zero cents"

Some other example input and output:

dollars "0" => "zero dollars and zero cents"

dollars "1" => "one dollar and zero cents"

dollars "0.1" => "zero dollars and ten cents"

dollars "1." => "one dollar and zero cents"

dollars "0." => "zero dollars and zero cents"

dollars ".34" => "zero dollars and thirty-four cents"

dollars "0.3456789" => "zero dollars and thirty-four cents"

dollars "1.0" => "one dollar and zero cents"

dollars "1.01" => "one dollar and one cent"

dollars "1000456.13" => "one million four hundred and fifty-six dollars and thirteen cents"