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

Prefix option for number_to_human_size #327

Closed
wants to merge 1 commit into from
Closed

Conversation

dcrec1
Copy link
Contributor

@dcrec1 dcrec1 commented Apr 28, 2011

As @trejkaz mentioned, in some cases it's useful to use the SI prefix when formatting bytes. I understand why this is not the default, but the related patch added a :prefix option to number_to_human_size so the developer can choose what to display in each scenario.

@josevalim
Copy link
Contributor

In which cases is useful to display a wrong information? :)

@hakanai
Copy link

hakanai commented Apr 28, 2011

This version is fine by me. Some people might want the third option (binary with the correct prefix) but in our application we're only using the SI version.

@dcrec1
Copy link
Contributor Author

dcrec1 commented Apr 28, 2011

@josevalim Mac OS X e Ubuntu, for example, are operating systems that use the SI prefix. As today, if you choose to upload to a Rails application a 1 MB file and then you format the number of bytes in the server to display it back to the user, the result will not be 1 MB.

@josevalim
Copy link
Contributor

touchez. applied!

@josevalim josevalim closed this Apr 28, 2011
brunoadacosta pushed a commit to brunoadacosta/rails that referenced this pull request Apr 28, 2011
Prefix option for number_to_human_size
@@ -304,6 +304,7 @@ module ActionView
# * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+)
# * <tt>:prefix</tt> - If +:si+ formats the number using the SI prefix (defaults to :binary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the default specified as :binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 346. If :prefix is different than :si, the binary base will be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. But then there is no :binary symbol involved here, right? I can give any value to :prefix to get the binary behavior(1024).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because as the relative base will not be found, the default will be used.

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

Successfully merging this pull request may close these issues.

None yet

4 participants