montopolis/fda-nutrition-rounding-php

This package is abandoned and no longer maintained. No replacement package was suggested.

Library for rounding nutrition values according to FDA guidelines.

v1.0.4 2021-09-03 04:22 UTC

This package is auto-updated.

Last update: 2024-08-29 04:20:01 UTC


README

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.