diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7caec1..20131a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,10 +6,16 @@ All notable changes to Divisor will be documented in this file.
> and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
> Major and Minor updates will get entries, patches may not get mentions.
-## [1.0.2] - 2023/08/26
+
+## [1.1.0] - 2023/08/26
+
+### Fixed
+
+- Form validation: null and space ignored and leading decimal, comma, or non-numeric values are ignored.
### Added
+- Rounding error in 3rd column
- Google Analytics
## [1.0.1] - 2023/07/29
@@ -26,7 +32,7 @@ All notable changes to Divisor will be documented in this file.
### Changed
-- Enabled divisor selection, default value is `1/16`. When divisor is changed, input fields are cleared.
+- Enabled divisor selection, default value is $`\frac{1}{16}`$. When divisor is changed, input fields are cleared.
### Added
diff --git a/package.json b/package.json
index b2793d4..4e29f46 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "divisor",
- "version": "1.0.2",
+ "version": "1.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/brio50/divisor.git"
diff --git a/public/index.html b/public/index.html
index a731146..4a0332c 100644
--- a/public/index.html
+++ b/public/index.html
@@ -15,17 +15,18 @@
-->
Divisor
-
-
-
-
+
- gtag('config', 'G-WJZ725QBFJ');
-
+
@@ -64,7 +65,7 @@
diff --git a/src/App.js b/src/App.js
index fcbebaf..fa5736c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -33,6 +33,8 @@ function App() {
// rounding
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
+ var error = Number(0); // global
+
function precision(x) { return (Math.round(x * 1000) / 1000) };
function round2divisor(x, divisor) { return (Math.ceil(x * divisor) / divisor) };
function nearest(value, divisor, option) {
@@ -72,7 +74,10 @@ function App() {
numerator = 0;
}
- console.log(`value = ${value} valueFeet = ${valueFeet} valueInch = ${valueInch} : wholeFeet = ${wholeFeet} wholeInch = ${wholeInch} fraction = ${numerator}/${denominator}`)
+ // round up, subtract value
+ error = (ft2in(wholeFeet) + wholeInch + (numerator / denominator)) - value;
+
+ console.log(`value = ${value} valueFeet = ${valueFeet} valueInch = ${valueInch} : wholeFeet = ${wholeFeet} wholeInch = ${wholeInch} fraction = ${numerator}/${denominator}, error = ${error}`)
// format output strings
switch (option) {
@@ -109,7 +114,7 @@ function App() {
// react Hook for state management - one per html tag
const [divisor, setDivisor] = useState(16); // default value
- const fields = { input: [], output: '' } // global
+ const fields = { input: [], output: '', error: [] } // global
const [millimeters, setMM] = useState(fields);
const [inches, setIN] = useState(fields);
const [feet, setFT] = useState(fields);
@@ -120,13 +125,27 @@ function App() {
// TODO: mathematical expressions (only allow +, -, *, / symbols) keyed on = as input?
function validateMeasurement(event) {
- const value = event.target.value;
+ var value = event.target.value;
function parseValue(value) {
- // replace , with .
+
+ // do not allow null OR space
+ if ( !value || value.match(/\s/) ) {
+ return "";
+ }
+
+ // do not allow leading decimal, comma, or non-numeric
+ if ( value.match(/^(\.|\,|[^0-9])/) ) {
+ value = "0.";
+ }
+
// limit input to *(.|,)#### (4 decimal places)
// does not allow letters, or any symbols other than . or ,
- const regex = /([0-9]*[.|,]{0,1}[0-9]{0,4})/s;
- return value.match(regex)[0].replace(/,/, ".");
+ const regex = /\d+(\.|\,){0,1}\d{0,4}/s;
+
+ if ( value.match(regex)[0] ) {
+ return value.match(regex)[0].replace(/\,/, ".");
+ }
+
}
return (parseValue(value));
}
@@ -152,19 +171,22 @@ function App() {
setMM({
...millimeters,
input: value,
- output: precision(value)
+ output: precision(value),
+ error: precision(0)
});
setIN({
...inches,
input: precision(mm2in(value)),
- output: nearest(mm2in(value), divisor, 'in')
+ output: nearest(mm2in(value), divisor, 'in'),
+ error: precision(error)
});
setFT({
...feet,
input: precision(in2ft(mm2in(value))),
- output: nearest(mm2in(value), divisor, 'ft-in')
+ output: nearest(mm2in(value), divisor, 'ft-in'),
+ error: precision(error)
});
};
const onChangeIN = (event) => {
@@ -174,19 +196,22 @@ function App() {
setMM({
...millimeters,
input: precision(in2mm(value)),
- output: precision(in2mm(value))
+ output: precision(in2mm(value)),
+ error: precision(error)
});
setIN({
...inches,
input: value,
- output: nearest(value, divisor, 'in')
+ output: nearest(value, divisor, 'in'),
+ error: precision(error)
});
setFT({
...feet,
input: precision(in2ft(value)),
- output: nearest(value, divisor, 'ft-in')
+ output: nearest(value, divisor, 'ft-in'),
+ error: precision(error)
});
};
const onChangeFT = (event) => {
@@ -196,19 +221,22 @@ function App() {
setMM({
...millimeters,
input: precision(in2mm(ft2in(value))),
- output: precision(in2mm(ft2in(value)))
+ output: precision(in2mm(ft2in(value))),
+ error: precision(error)
});
setIN({
...inches,
input: precision(ft2in(value)),
- output: nearest(ft2in(value), divisor, 'in')
+ output: nearest(ft2in(value), divisor, 'in'),
+ error: precision(error)
});
setFT({
...feet,
input: value,
- output: nearest(ft2in(value), divisor, 'ft-in')
+ output: nearest(ft2in(value), divisor, 'ft-in'),
+ error: precision(error)
});
};
@@ -247,32 +275,25 @@ function App() {
-
+
Millimeters
+
+
+ {millimeters.output} mm
+ {millimeters.error}
+
-
Millimeters
-
-
-
- {millimeters.output} mm
-
-
-
-
Inches
-
-
-
- {inches.output || 'in'}
-
-
-
-
Feet
-
-
-
- {feet.output || 'ft'}
-
-
+
Inches
+
+
+ {inches.output || 'in'}
+ {inches.error}
+
+
Feet
+
+
+ {feet.output || 'ft'}
+ {feet.error}