INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Formatting numbers to two decimal places WITH zeros?  (Read 1219 times)

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Formatting numbers to two decimal places WITH zeros?
« on: April 15, 2013, 07:22:36 am »

FormatNumber() allows us to specify the number of decimal places but it seems to truncate ZEROS from the display,

eg displaying

2.2

instead of

2.20

Any way around this??
Logged

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Formatting numbers to two decimal places WITH zeros?
« Reply #1 on: April 15, 2013, 11:47:25 am »

It is ugly:

if(isequal(length(listitem(formatnumber(2.201,2),1,/,)),2,4),formatnumber(2.201,2)0,formatnumber(2.201,2))

(In my locale comma is used as the decimal point, so you might want to change "/," to ".".)
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Formatting numbers to two decimal places WITH zeros?
« Reply #2 on: April 16, 2013, 01:39:57 am »

Very close but I'm getting integer numbers, eg 2, coming out as 20

It's a shame format number doesn't do the padding.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Formatting numbers to two decimal places WITH zeros?
« Reply #3 on: April 16, 2013, 02:44:29 am »

I agree - FormatNumber() should do what it is asked, since its purpose is to format a number.

Here's another option:

   regex(0[your field], /#^(\d+)?(?:\.(\d+))?#/, -1)formatnumber([R1],0).left([R2]000000000,2)

It doesn't deal with empty values (turns them into 0.00).  Change the red value to the number of decimal places you want.

See also:

    http://yabb.jriver.com/interact/index.php?topic=69377.msg467279#msg467279
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Formatting numbers to two decimal places WITH zeros?
« Reply #4 on: April 16, 2013, 02:48:46 am »

Thanks, MrC. I obviously did not get it right.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Formatting numbers to two decimal places WITH zeros?
« Reply #5 on: April 16, 2013, 03:00:41 am »

Your method works with a listcount() == 2.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up