Show blank for zero values

Questions, tips and tricks and techniques for scripting in Servoy

Show blank for zero values

Postby faheemhameed » Sun Dec 05, 2004 3:14 pm

How can I format a numeric field to show blanks if it contains a zero?

Thanks
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Postby Jan Blok » Mon Dec 06, 2004 12:40 pm

use # - (zero shows as absent)
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam

Postby faheemhameed » Mon Dec 06, 2004 1:48 pm

Thanks! I would try that.
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Postby faheemhameed » Fri Apr 01, 2005 7:18 pm

Hi Jan,

This does not work completely.

I have a value 0 in a number field. I just # as format. But it shows the 0 instead of blank

Thanks
Hameed
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Postby faheemhameed » Fri Apr 01, 2005 7:25 pm

Also when I clear the number field, it puts a zero by default. But I have not set any default value. How to overcome that please.

Thanks
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Postby Jan Blok » Fri Apr 22, 2005 2:48 pm

It seems a bug from SUN, in the docs they say # - show 0 as absent
http://java.sun.com/j2se/1.4.2/docs/api ... ormat.html
but it does not show, we will report this to SUN.

BTW it seems sort of working (zero not shown) when "#.00" is used as format
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam

Postby sebster » Mon May 30, 2005 11:58 am

Actually the docs are probably a bit lousy, but this is really expected behavior. The # means blank *padding*, that is, "###" with the number 3 for example is shown as " 3". However, it will always output a number (and never a total blank), so "###" with the number 0 becomes " 0".

The comment from the SUN source code is clearer than the JavaDoc:

// Handle patterns with no '0' pattern character. These patterns
// are legal, but must be interpreted. "##.###" -> "#0.###".
// ".###" -> ".0##".

/* We allow patterns of the form "####" to produce a zeroDigitCount of
* zero (got that?); although this seems like it might make it possible
* for format() to produce empty strings, format() checks for this
* condition and outputs a zero digit in this situation.

Thus this behavior is intentional.

I'm afraid you're going to have to find a different way of displaying an empty string for the number zero... (maybe using a calculation).
Sebastiaan van Erk
Servoy
sebster
 
Posts: 251
Joined: Thu Apr 24, 2003 10:03 am
Location: Utrecht, The Netherlands

Re: Show blank for zero values

Postby martinh » Tue Jan 24, 2012 1:18 pm

Last post on this subject was 2005.

Now it is 2012 and Servoy 5.2 / 6.0

Is there already a solution for this situation?

I have a column in the database numeric(9, 4)

Default format is #,##0.00##

So it shows:

DB Value Format
5,0000 5,00
5,2500 5,25
5,2570 5,257

But in case of value 0, I would like to see an empty field (so blank when zero).
Otherwise I must allow NULL values in the database and let 0 be a NULL value, but that is not really what I prefer.
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Re: Show blank for zero values

Postby jcompagner » Tue Jan 24, 2012 1:25 pm

this is just how the formatting works
and if you have a 0 then you have a 0, that is really not the same a null (which is nothing)

if you want something else, what you can do is place a converter in between, so that 0 are converted to null and visa versa i guess
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8284
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: Bing [Bot] and 2 guests