I have a string in my payload that looks like this:
I need to convert it to a number, and remove the dot (while keeping the two decimals)
Would anyone know how to do this?
in a function node...
msg.payload.totalPaid = parseFloat(msg.payload.totalPaid) * 100;
It works fine for some numbers but others come out like this:
Yes, some numbers cannot be represented accurately (this is a floating point thing)
One workaround is to round it...
Tried that now, but it is returned as a string?
This is the input:
This is the code:
msg.payload.netPrice = Math.round(parseFloat(msg.payload.netPrice) * 100);
And this is the output (should be 15120 without quotes):
The code will return a number - you must have some mistake.
Did you deploy? Are you running new changes?
Your code actually works perfectly outside of my subflow (below). This is what I'm trying to do.
I am using this:
To iterate over an array
line_items where there is a key named
total inside each object.
For each iteration, I am using a change node to change
This works perfectly.
Then I need to convert that value (
netPrice) into the forementioned format.
Tried placing the function node here, but that did not work:
Placing it before or after my subflow doesn't work either without specifying which object.
There's no need for loops. Use the split node, do your changes, use a join node to put it all back together?
How do I achieve the same thing with the split node? I found a solution that works really well for my use case but the number formatting is the only thing missing
Share your flow and some sample data & I'll show you.
To get sample data add a debug node to where the data comes from & use the "copy value" that appears under your mouse pointer when you over hover a debug message property in the sidebar.
It looks like the split node will only split
msg.payload but I need to split
How do I configure it to do that?
add a change node to move or set
msg.payload to the value of
msg.payload.line_items BEFORE the split.
That worked, but now the rest of the payload is gone...
I understand that it's a lot easier to help if I share my flow, but in this case I think that will be difficult because the data I'm working with is pulled from an API that only I have access to.
The only thing remaining that I need help with now is to combine two messages into one.
So I have two messages that each have an array that is called the same (
I need to combine them so that I get one message, with an array called
line_items, that has both of the objects inside it (or more, if one of the message's array contains multiple objects).
I have tried using the join node i manual mode with different type of settings, but the closest I can get is this, where the arrays are placed inside a new array:
But I need the object to be in the array directly, if that makes sense?
Like this (photoshopped):
That doesn't look like source data since it has
"netPrice":15920 also, I don't see your flow (can you share what you currently have)
I'm sorry but I odn't think I can provide the info you ask for.
Does anyone else maybe know how I can merge these two into one?
Why not? Is it sensitive? Or do you not know how?