Skip to content

Instantly share code, notes, and snippets.

@nateflink
Created June 27, 2018 03:26
Show Gist options
  • Save nateflink/e6c7e471e0bcf895c8d3c6e273901e06 to your computer and use it in GitHub Desktop.
Save nateflink/e6c7e471e0bcf895c8d3c6e273901e06 to your computer and use it in GitHub Desktop.
pad dollars
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