Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for /lib/origami/numeric.rb #16

Closed
GoogleCodeExporter opened this issue Dec 30, 2015 · 4 comments
Closed

Patch for /lib/origami/numeric.rb #16

GoogleCodeExporter opened this issue Dec 30, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Using %g causes bad formatting - for example 0.000001 is formatted as 1.0e-06

Original issue reported on code.google.com by davejohn...@gmail.com on 24 Oct 2012 at 6:12

@GoogleCodeExporter
Copy link
Author

Oops - the regex is incorrect.  brb.

Original comment by davejohn...@gmail.com on 24 Oct 2012 at 6:17

@GoogleCodeExporter
Copy link
Author

The regex should be this:

sprintf("%f", self).sub(/(?:\.0*$)|(\.\d*[^0]+)0*$/, '\1')

Seems to work better:
irb(main):014:0> [0, 0.000001, 344, 344.5, 344.55, 344.05, 344.0506].each { |a| 
puts sprintf("%f", a).sub(/(?:\.0*$)|(\.\d*[^0]+)0*$/, '\1') }
0
0.000001
344
344.5
344.55
344.05
344.0506

Original comment by davejohn...@gmail.com on 24 Oct 2012 at 6:29

@GoogleCodeExporter
Copy link
Author

OK - home now and off my bike.  I simplified the regex a bit:

sprintf("%f", self).sub(/\.0*$|(\.\d*[^0])0*$/, '\1')

irb(main):004:0> [10110, 1011, 10.11, 1.011, 0.1011, 0.01011, 0.001011].each { 
|a| puts sprintf("%f", a).sub(/\.0*$|(\.\d*[^0])0*$/, '\1') }
10110
1011
10.11
1.011
0.1011
0.01011
0.001011

Original comment by davejohn...@gmail.com on 24 Oct 2012 at 8:12

@GoogleCodeExporter
Copy link
Author

Thank you, I committed your last version :)

Original comment by guilla...@security-labs.org on 20 Dec 2012 at 4:18

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant