178
Views
4
Comments
Solved
reduce decimal digits without rounds
Question

how to trim the decimal digits to only one digit 3.58333333333333333333333333333

to become  3.5 


i want to show only  3.5  from 3.58333333333333333333333333333  without round 

and FYI it might have decimal digits and it might not have 

i want the result to be 


3.58333333333333333333333333333  = 3.5

3 = 3

1 = 1

1.5  = 1.5



2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi Omar,


You can create a simple function to do this. The formula would be the one below, where Number is the number you want to reduce and DecimalPlaces represent the number of places you want to retain:



The algorithm goes like this:


  • You have 3.51666 and you want to reduce it to 2 decimal places
  • So the number is multiplied by 100 (which is 10^<DecimalPlaces>), and you get 351.6666
  • The number is truncated, so you get 351
  • The number is divided by the 100  (which is 10^<DecimalPlaces>) again, and you would get the 3.51


Kind Regards,
João

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

An even simpler way, if one always wants to truncate after the first decimal, would be to multiply by ten, cast to an integer, then divide by ten:

DecimalToInteger(MyDecimal * 10) / 10
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

An even simpler way, if one always wants to truncate after the first decimal, would be to multiply by ten, cast to an integer, then divide by ten:

DecimalToInteger(MyDecimal * 10) / 10
2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi Omar,


You can create a simple function to do this. The formula would be the one below, where Number is the number you want to reduce and DecimalPlaces represent the number of places you want to retain:



The algorithm goes like this:


  • You have 3.51666 and you want to reduce it to 2 decimal places
  • So the number is multiplied by 100 (which is 10^<DecimalPlaces>), and you get 351.6666
  • The number is truncated, so you get 351
  • The number is divided by the 100  (which is 10^<DecimalPlaces>) again, and you would get the 3.51


Kind Regards,
João

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

An even simpler way, if one always wants to truncate after the first decimal, would be to multiply by ten, cast to an integer, then divide by ten:

DecimalToInteger(MyDecimal * 10) / 10
2025-02-10 17-24-13
Arun Rajput

Hi @Omar AbdElhadi ,

Use FormatDecimal() inbuilt function of outsystems.

Regards,

Arun 

2023-01-26 16-03-24
Ana Agostinho

Hello @Arun Rajput

Your answer does not satisfy the requirements asked by Omar. Take a look at the documentation: 

Omar explicitly said, "without rounding".

Best regards, 

Ana

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.