This topic was automatically generated from Slack. You can find the original thread here.
How do i remove any . or , from a number? i want to keep any digit thats a number and remove anything else. Is there a formatting function in the flow?
This topic was automatically generated from Slack. You can find the original thread here.
How do i remove any . or , from a number? i want to keep any digit thats a number and remove anything else. Is there a formatting function in the flow?
To remove any periods (.) or commas (,) from a number and keep only the digits in a Pipedream workflow, you can use the Formatting app with a custom JavaScript code step, as there isn’t a direct pre-built action for this specific task in the Formatting app. Here’s how you can do it: 1. Add a new step to your workflow. 2. Choose the Run Node.js code action. 3. In the code editor, write the following JavaScript code: export default defineComponent({ async run({ steps, $ }) { // Assuming `inputNumber` is the number you want to format, as a string const inputNumber = "1,234.56"; // Replace this with your actual input // Remove any periods (.) or commas (,) const formattedNumber = inputNumber.replace(/[.,]/g, ""); return formattedNumber; }, });
This code takes a string inputNumber
, which represents your number with periods and commas, and uses the replace
method with a regular expression to remove all occurrences of periods and commas. The result is a string formattedNumber
that contains only the digits from the original number. Remember to replace "1,234.56"
with the actual input you’re working with, which could be a variable or a value from a previous step in your workflow.
Im getting the number from previous step with the path steps.ExtractSEKSWISH.$return_value
To access the number from the previous step named ExtractSEKSWISH
in your Pipedream workflow, you can use the steps
object in the following way: const number = steps.ExtractSEKSWISH.$return_value;
This code snippet will assign the value returned by the ExtractSEKSWISH
step to the variable number
. You can then use this variable in your current step for further processing or actions as needed.
How do i remove any . or , from a number? i want to keep any digit thats a number and remove anything else. Is there a formatting function in the flow?
Im getting the number from previous step with the path steps.ExtractSEKSWISH.$return_value
To remove any .
or ,
from a number and keep only the digits in a Pipedream workflow, you can use the Formatting app with a custom JavaScript code step. While there isn’t a pre-built Formatting action specifically for removing characters, you can achieve this using JavaScript’s replace
method within a code step. Here’s how you can set it up: 1. After the step that extracts the number (which you’ve referred to as steps.ExtractSEKSWISH.$return_value
), add a new step. 2. Choose the Run Node.js code option to add a custom code step. 3. In the code step, use the following JavaScript code to remove any .
or ,
from the extracted number: export default defineComponent({ async run({ steps, $ }) { // Retrieve the number from the previous step const numberString = steps.ExtractSEKSWISH.$return_value; // Use a regular expression to remove any . or , from the number const cleanedNumber = numberString.replace(/[.,]/g, ""); // Return the cleaned number return cleanedNumber; }, });
This code retrieves the number from the steps.ExtractSEKSWISH.$return_value
path, uses a regular expression to find and replace all occurrences of .
and ,
with an empty string (effectively removing them), and then returns the cleaned number. Remember, you’ll need to replace ExtractSEKSWISH
with the actual step ID of the step that extracts the number in your workflow. You can find the step ID by looking at the left side of the step in the Pipedream workflow editor.
im running code below and getting the error “TypeError
numberString.replace is not a function”
export default defineComponent({
async run({ steps, $ }) {
// Retrieve the number from the previous step
const numberString = steps.ExtractSEKSWISH.$return_value;
// Use a regular expression to remove any . or , from the number
const cleanedNumber = numberString.replace(/[.,]/g, "");
// Return the cleaned number
return cleanedNumber;
},
});
The error you’re encountering, “TypeError numberString.replace is not a function”, suggests that numberString
is not a string, as the .replace
method is only available on string objects. This could happen if steps.ExtractSEKSWISH.$return_value
is returning a number or another data type instead of a string. To resolve this issue, you can ensure numberString
is treated as a string by explicitly converting it using the String
function before applying the .replace
method. Here’s how you can modify your code: export default defineComponent({ async run({ steps, $ }) { // Retrieve the number from the previous step const numberString = steps.ExtractSEKSWISH.$return_value; // Ensure numberString is treated as a string const stringifiedNumber = String(numberString); // Use a regular expression to remove any . or , from the number const cleanedNumber = stringifiedNumber.replace(/[.,]/g, ""); // Return the cleaned number return cleanedNumber; }, });
This modification uses the String
function to convert numberString
to a string, ensuring that the .replace
method can be called without errors.