Format data from a source in string to our own format
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2021
08:16 AM
12-25-2021
08:16 AM
Format data from a source in string to our own format
Hi team,
can somebody pls help me?
i have an interest rate coming from a source is "00550" and "02000"
How can I convert it to 0.550 or 0.550?
02.000 or 2.000?
Thanks
Labels:
- Labels:
-
Assertions
-
REST
-
Scripting
-
SOAP
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2021
09:23 AM
12-27-2021
09:23 AM
Hey @shiva1020243,
Can you provide more info to clarify?
When you say "source", are you using the datasource functionality? If "yes", how are you using it?
Or, is the numerics a value in a response?
Cheers,
Rich
Can you provide more info to clarify?
When you say "source", are you using the datasource functionality? If "yes", how are you using it?
Or, is the numerics a value in a response?
Cheers,
Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2021
04:20 PM
12-27-2021
04:20 PM
Hello @shiva1020243
Here is some groovy script code that can do what you request. Given your ambiguous requirement, I made best guess at a response... 🙂
There are two sections of the code that are identical just to show different originating source values and their outcome.
Regards,
Todd
import java.text.DecimalFormat;
df = new DecimalFormat("#0.000");
interestRateStr = "00550";
interestRateInt = interestRateStr.toInteger();
interestRateFloat = interestRateInt / 1000;
log.info "interestRateFloat=$interestRateFloat";
finalValue = df.format(interestRateFloat);
log.info "finalValue=$finalValue";
interestRateStr = "02000";
interestRateInt = interestRateStr.toInteger();
interestRateFloat = interestRateInt / 1000;
log.info "interestRateFloat=$interestRateFloat";
finalValue = df.format(interestRateFloat);
log.info "finalValue=$finalValue";
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022
04:40 AM
01-19-2022
04:40 AM
Thanks everyone!
Hi @shiva1020243, does the advice from the Community help? Please let us know.
Sonya Mihaljova
Community and Education Specialist
