From the course: Ruby on Rails 6: Controllers and Views
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Number helpers - Ruby on Rails Tutorial
From the course: Ruby on Rails 6: Controllers and Views
Number helpers
- [Instructor] Ruby on Rails includes many methods that are designed to help you to format numbers. There's number_to_currency, number_to_percentage, number_with_precision, which is also aliased as number_to_rounded, number_with_delimiter, which is aliased as number_to_delimited, number_to_human, number_to_human_size, and number_to_phone. All of these helper methods take a number as their first argument and then a hash of options as their second argument. But you only need to provide that hash if you want to override the Rails defaults. For most of those, they take a couple of standard options. Delimiter, which delimits the thousands and the default is a comma. Separator, which is the decimal separator and its default is the period. And precision, the number of decimal places to show. It varies a little bit between the methods but it's typically two or three. Let's take a look at the first one, number_to_currency. If you…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.