Hello!

Iâ€™m not sure Iâ€™m asking this correctly.

Iâ€™d like to eliminate the .00 after my numbers but â€śPrecision 1â€ť rounds the numbers (which I donâ€™t want).

I need whole numbers with no .00 if possible.

Is there an alternative?

Thanks

Hello!

Iâ€™m not sure Iâ€™m asking this correctly.

Iâ€™d like to eliminate the .00 after my numbers but â€śPrecision 1â€ť rounds the numbers (which I donâ€™t want).

I need whole numbers with no .00 if possible.

Is there an alternative?

Thanks

Are you saying that sometimes you do have decimal amounts, but you want to truncate the decimal instead of round it? Just basing off your examples you have .00, so there would be no rounding taking place if you set precision to 1. Just want to make sure I understand what kinds of numbers you are working with. There are math formulas such as Floor or Trunc which would work for you, but Iâ€™m not sure you need to take it that far.

Would be better if we hear from him what he expects in these test cases:

123.00

123.01

123.06

1 Like

Thanks for the reply.

These are mostly going to be whole numbers usually with occasional .5:

â€śThis is a 1 spreadâ€ť (rather than 1.0 spread)

â€śThis spread is 1.5â€ť (and 1.50 is fine here)

â€śThis is a 2.25 spreadâ€ť (perfect, not rounded up)

â€śThis is a 2.5 spreadâ€ť (this is fine because 2.5 and 2.50 works for us, here)

In the column called premium weâ€™d prefer:

â€śPremium (cr) .12â€ť (rather than 0.12)

Also for the sleg column, most of those whole numbers end with 5 or 0.

â€ś225â€ť (not 225.00)

â€ś225.50â€ť (without rounding up but 225.5 is ok here too).

Hope that makes sense.

I donâ€™t know if that cleared things up or made me more confused. Is this more of a cosmetic thing where you just want to remove any leading or trailing zeros?

Please answer the question from @ThinhDinh â€¦

Given each of the above, what would you expect as the output?

1 Like

Yes.

Try this in a javascript column. The p1 parameter would be your number.

```
function trimLeadingAndTrailingZeros(number) {
// Convert number to string
let strNum = String(number);
// Trim leading zeros
strNum = strNum.replace(/^0+/, '');
// Trim trailing zeros
strNum = strNum.replace(/0+$/, '');
// Check if number is valid
if (isNaN(strNum) || !strNum) {
return '0';
}
return strNum;
}
return trimLeadingAndTrailingZeros(p1)
```

2 Likes

Thank you. Iâ€™m too new to understand what to do with that information, though.

Where do I put it?

Ohhhhh!???

All of the Glide community help posts I ran search implied JavaScript wasnâ€™t supported.

So itâ€™s in a column now! Got it!

Will implement ASAP and report back!

Thanks Jeff!

1 Like

JavaScript is not supported on the front end, such as in a Rich Text component, or injecting javascript some other way. Itâ€™s always been available through the back end in the table as a column type.

1 Like

First of all, thank you for this. Much appreciated.

Secondly, am I to understand that I would need to create a javascipt column for each number I need?

If you mean you need them to format different columns, then yes, each column requires a JS companion.

1 Like

Let me rephrase what I mean.

I understand the script will format the column.

So in this case will (p1) be the same number on every row in this case the .21

OR

Is there a way to adjust this so that I can have the script trimming each of the numbers in a column instead of just one number I put in p1?

You are specifying a column for your p1 parameter. With that, the javascript will run for each value in each row. It would only be the same if you were to hard coded an actual number instead of specifying a column.

With that, the code you copied and pasted doesnâ€™t appear to be formatted the same as what I shared, which is leading the the error you are seeing. Itâ€™s important that it looks the same.

For what itâ€™s worth, you can get the same effect as the JavaScript with an if-then-else column:

This is something I stumbled upon a couple of months ago. As long as you have at least two IF cases, it will work - in the sense that fractional numbers have trailing zeros removed, and exact numbers are returned whole. I accidentally discovered this behaviour whilst looking for a solution for a client that had *exactly* this requirement.

6 Likes

Thank you kindly! Iâ€™ll implement pronto and report back!

What a nice hidden â€śfeatureâ€ť. Very random (no pun intended) but useful. I have no idea how I could remember that though

2 Likes

This is pure magic.

2 Likes