-
-
Save nateflink/e6c7e471e0bcf895c8d3c6e273901e06 to your computer and use it in GitHub Desktop.
pad dollars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val = "32.244" | |
if val.is_a? String | |
if val.match /\d+\.\d\d$/ | |
val | |
elsif val.match /(\d+\.\d\d)\d+$/ | |
$1 | |
elsif val.match /\d+\.\d$/ | |
val+'0' | |
elsif val.match /\d+\.$/ | |
val+'00' | |
elsif val.match /\d+$/ | |
val+'.00' | |
end | |
else | |
#error value is not a string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment