Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Library for rounding nutrition values according to FDA labelling guidelines.

License

Notifications You must be signed in to change notification settings

montopolis/fda-nutrition-rounding-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FDA Nutrition Rounding in PHP

Basic library for rounding nutritional information according to FDA guidelines (source)

Install

You can add the library to your existing project using Composer:

composer require montopolis/fda-nutrition-rounding-php

Usage

<?php

$rounder = new Montopolis\Fda\Rounding();

$rounder->calorie(123)->toInt(); // outputs 120
$rounder->calorie(123)->toFloat(); // outputs 120.0
$rounder->calorie(123)->toString(); // outputs "120 g"

$rounder->carbohydrate(0.51)->toString(); // outputs "less than 1 g"

Supported nutrient types

At the time of writing, the library supports all nutrient types defined by the FDA guidelines.

$rounder->alcohol($value)->toInt();
$rounder->betaCarotene($value)->toInt();
$rounder->calorie($value)->toInt();
$rounder->carbohydrate($value)->toInt();
$rounder->cholesterol($value)->toInt();
$rounder->dietaryFiber($value)->toInt();
$rounder->fat($value)->toInt();
$rounder->mineral($value)->toInt();
$rounder->otherFiber($value)->toInt();
$rounder->potassium($value)->toInt();
$rounder->protein($value)->toInt();
$rounder->sodium($value)->toInt();
$rounder->sugar($value)->toInt();
$rounder->vitamin($value)->toInt();

Run the tests

./vendor/bin/phpunit
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

.........

Time: 100 ms, Memory: 4.00MB

OK (9 tests, 46 assertions)

License

The MIT License (MIT). Please see License File for more information.

About

Library for rounding nutrition values according to FDA labelling guidelines.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages