Join Kevin Skoglund for an in-depth discussion in this video Improve float formatting, part of Easy PHP Projects: Measurement Conversion.
- In this movie, we will write a custom .php function…that can improve the formatting…of our floating point numbers.…Open up your functions.php file,…and in there, right under optionize,…we're going to add a new function.…One of the nice things about adding it as a function…is that then it becomes a function…that we can pull and reuse in other projects, if we need to.…So let's call this function float_to_string,…and that's going to be our custom function…that will allow us to convert a floating point number…into a string in the way that we want.…
So let's have as an argument the float…that we're going to pass in, and inside here…we're going to use that number format…as a basis that we saw earlier.…The number format is going to take…a couple of arguments.…The first one is going to be the float itself.…The second one is going to be the precision.…That's going to be a number that tells us…how many decimal places we want to have.…Now, we could have that as a hard-coded value…in here, but I'm going to go ahead…and make that flexible by making it…
Along the way, series designer Kevin Skoglund introduces coding strategies, refactoring techniques, and useful skills including dynamically generating form select-option values and formatting decimal numbers and scientific notation.
- Converting length and area measurements
- Using functions to avoid repetition
- Refactoring to produce simpler code
- Converting volume and mass
- Generating form select-option values dynamically
- Formatting scientific notation
- Converting speed and temperature
Skill Level Beginner
Accessing Databases with Object-Oriented PHPwith David Powers3h 47m Intermediate
1. Length and Distance
3. Volume and Capacity
4. Mass and Weight
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.