Hello,
I need to make a decimal number with only three digits after the comma without doing the round function.
Thank you
Hello,
I need to make a decimal number with only three digits after the comma without doing the round function.
Thank you
Can you give some examples like how your input number will be and how you want the output?
Exemple : input 271.7815
Output: 271.781
one of many options: cutting off with regex:
Sorry I don t know how to really use regex
you can use the protoyped line from immediate panel in an assign activity like
Assign Activity:
myNumberAsString = Regex.Match(MyNumber.TosString,“\d+.\d{0,3}”).Value
Ensure following:
Thats all we need to do
e.g. https://regex101.com/ also explains us the patterns:
Let me check also for an alternate approach
we should keep in mind that we can do it on a string base. But we don’t know the variations and if we can rely on the presence of the decimal dot and a minimum decimal part length. Otherwise we are risking exceptions.
For a defensive retrieval of the 2 parts (before/after Dot) we can do (but looks more complicating the things)
as we can see, no error is reported in case we have no dot or decimal part length < 3
Along with this variation:
String.Format(“{0:0.000}”,YourDoubleValue)
Hi @Loha,
You can use this for another solution.
“271.7815”.Split(“.“c)(0)+”.”+“271.7815”.Split("."c)(1).Substring(0,3)
Regards,
MY
Thank you all.
I was able to resolve my problem by using
Math.truncate(decimal.parse(myStr)*1000)/1000
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.