Update round.js
This commit is contained in:
parent
55e3b09415
commit
6e97f00d52
1 changed files with 6 additions and 14 deletions
|
|
@ -4,47 +4,40 @@ export default {
|
||||||
bytecodeKey: "round",
|
bytecodeKey: "round",
|
||||||
name: "Round/Floor/Ceiling",
|
name: "Round/Floor/Ceiling",
|
||||||
color: 120,
|
color: 120,
|
||||||
description: "Round a value to the nearest whole number via round, floor, or ceiling functions",
|
description: "Convert decimal numbers to whole numbers using different rounding strategies. Perfect for cleaning up sensor readings (23.7°F → 24°F), creating clean display values (3.14159 → 3), or preparing data for systems that only accept integers. Choose round for normal rounding, floor for always rounding down, or ceiling for always rounding up.",
|
||||||
|
|
||||||
connections: {
|
connections: {
|
||||||
mode: "value",
|
mode: "value",
|
||||||
output: "expression",
|
output: "expression",
|
||||||
},
|
},
|
||||||
|
|
||||||
inputs: {
|
inputs: {
|
||||||
VALUE: {
|
VALUE: {
|
||||||
description: "A value you'd like to round to a whole number. Will be coerced to a number.",
|
description: "The decimal number you want to convert to a whole number. Examples: sensor readings like 72.8°F, calculated values like 3.14159, or any numerical data that needs to be simplified. Non-numeric values will be automatically converted to numbers where possible.",
|
||||||
bytecodeProperty: "value",
|
bytecodeProperty: "value",
|
||||||
check: "expression",
|
check: "expression",
|
||||||
shadow: "io_math_number"
|
shadow: "io_math_number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
OPERATION: {
|
OPERATION: {
|
||||||
description: "Select which rounding operation to perform on the input:",
|
description: "Choose how to convert your decimal to a whole number:",
|
||||||
options: [
|
options: [
|
||||||
["Round", "round", "if .5 or higher: round up; otherwise round down"],
|
["Round", "round", "Standard rounding: 0.5 or higher rounds up, below 0.5 rounds down (e.g., 23.7 → 24, 23.4 → 23, 23.5 → 24). Best for general use and displaying clean values."],
|
||||||
["Floor", "floor", "rounds down"],
|
["Floor", "floor", "Always rounds down to the nearest whole number, regardless of decimal value (e.g., 23.9 → 23, 23.1 → 23). Perfect for counting items, time calculations, or when you need conservative estimates."],
|
||||||
["Ceiling", "ceiling", "rounds up"],
|
["Ceiling", "ceiling", "Always rounds up to the nearest whole number, regardless of decimal value (e.g., 23.1 → 24, 23.9 → 24). Great for capacity planning, ensuring minimum values, or safety margins."],
|
||||||
],
|
],
|
||||||
bytecodeProperty: "operation",
|
bytecodeProperty: "operation",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
template: "%OPERATION %VALUE",
|
template: "%OPERATION %VALUE",
|
||||||
|
|
||||||
generators: {
|
generators: {
|
||||||
json: (block, generator) => {
|
json: (block, generator) => {
|
||||||
const
|
const
|
||||||
value = JSON.parse(generator.valueToCode(block, 'VALUE', 0)),
|
value = JSON.parse(generator.valueToCode(block, 'VALUE', 0)),
|
||||||
operation = block.getFieldValue('OPERATION'),
|
operation = block.getFieldValue('OPERATION'),
|
||||||
payload = { round: { value, operation } }
|
payload = { round: { value, operation } }
|
||||||
|
|
||||||
return [ JSON.stringify(payload), 0 ]
|
return [ JSON.stringify(payload), 0 ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
regenerators: {
|
regenerators: {
|
||||||
json: (blockObject, helpers) => {
|
json: (blockObject, helpers) => {
|
||||||
const
|
const
|
||||||
|
|
@ -55,7 +48,6 @@ export default {
|
||||||
fields = {
|
fields = {
|
||||||
OPERATION: operation,
|
OPERATION: operation,
|
||||||
}
|
}
|
||||||
|
|
||||||
return { type: 'io_math_round', inputs, fields }
|
return { type: 'io_math_round', inputs, fields }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue