Padding Numeric field with leading Zeros

Hi,

I have a situation where I need to convert an Amount field into a CHAR 
field and pad it with leading Zeros, so that the total number of places 
occupied are 12 characters.

for example :

If the amount is $4.50

Then it should be converted as 

000000000450

Has anyone done this in the past. If yes, could you please send me the 
methodology. Thanks.

Regards,

Murali.
0
Murali_Krishnamurthy
7/9/2003 8:47:19 PM
sybase.ase.general 8655 articles. 0 followers. Follow

1 Replies
1152 Views

Similar Articles

[PageSpeed] 14
Get it on Google Play
Get it on Apple App Store

declare @VALUE int
declare @i int
select @i = 9   -- number of characters desired
select @VALUE = -12345

/*  leading sign */

SELECT
  CASE
    WHEN @VALUE >= 0
     THEN "+" + right(replicate ("0", @i) + CONVERT(VARCHAR(9), 
ABS(@VALUE)), @i)
    ELSE  "-" + right(replicate ("0", @i) + CONVERT(VARCHAR(9), 
ABS(@VALUE)), @i)
  END

/* trailing sign */

SELECT
  CASE
    WHEN @VALUE >= 0
     THEN right(replicate ("0", @i) + CONVERT(VARCHAR(9), ABS(@VALUE)) , 
@i) + "+"
    ELSE  right(replicate ("0", @i) + CONVERT(VARCHAR(9), ABS(@VALUE)) , 
@i) + "-"
  END


/*  no sign  */

SELECT right(replicate ("0", @i) + CONVERT(VARCHAR(9), ABS(@VALUE)) , @i)

0
wkraatz
7/10/2003 2:35:12 PM
Reply:

Similar Artilces:

Padding Numeric field with leading Zeros #2
Hi, I have a situation where I need to convert an Amount field into a CHAR field and pad it with leading Zeros, so that the total number of places occupied are 12 characters. for example : If the amount is $4.50 Then it should be converted as 000000000450 Has anyone done this in the past. If yes, could you please send me the methodology. Thanks. Regards, Murali. ...

Pad Number with Leading Zeros
------_=_NextPart_001_01C146C3.16F952D0 Content-Type: text/plain; charset="iso-8859-1" Hello. Is there a way to pad a number with leading zeros with 1 command rather than the 2 I used below? It looks like you're supposed to be able to zero-fill with sprintf but I couldn't figure it out. #!/bin/perl -wd $f = 1234; $g = sprintf "%6s", $f; $g =~ s/ /0/g; print "$f\n"; print "$g\n"; ~Carl ------_=_NextPart_001_01C146C3.16F952D0-- ------_=_NextPart_001_01C146C7.025BA040 Content-Type: t...

How to pad string with leading zeroes
*** please ignore the post entitled 'Brian'. Its a duplicate of *** this post without a matching title Hi, I have a requirement to convert a 3-digit integer to a 3 character string padded with leading zeroes as I SELECT it from the database. Examples: ========= 1 converts to '001' 21 converts to '021' 321 converts to '321' I have played with several string functions to no avail. Any help/suggestions would be appreciated. Brian Two possible ways to get you going: select substring(convert(char(4),column + 1000),2,3) OR ...

Remove trailing zeros in numeric fields.
Some fields in my datagrid are bound to numeric fields in the SqlServer database. The default behavior is that the datagrid always displays numbers to the same precision as the database field. But I get trailing zeros. How can I format the datagrid just to display the significant digits? Hi, in BoundField, add this property: DataFormatString = "{0:F2}"You can see more in : http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx ---Eduardo DiasMCP, MCTS Web ApplicationsACM Professional MemberCSTA Individual MemberIASA Individual Member--------------------------------...

Replace leading zeros in character field
How do i replace leading zeros in a character field in a datawindow Example : 00012345, i would like that to be displayed as 12345. Thanks for help If the field only contains numbers, you could use string(number('00012345')). Attached is a generic replace function ( I thik I got it from the Code example that ships with PB) -- Terry Dykstra (TeamSybase) http://powerbuilder.codeXchange.sybase.com/ http://casexpress.sybase.com/cx/cx.stm product enhancement requests: http://my.isug.com/cgi-bin/1/c/submit_enhancement "chidu" <schidura@gmail.com> wrote in...

Output numeric column with leading zeros
I need to output two columns from a certain table in a fixed column width format to a text file. The string column is no big deal--it was covered in documentation. However, I can't figure out how to export a numeric column with forced size that may include leading/trailing zeros if necessary. How can I do that? The existing column formats are: varchar(18), numeric(7.1) I need output to a text file similar to: CCCCCCCNNNNNNN.N (no delimiter, number may need leading zeros) Please respond in email if possible. Virtually yours, <orlan@hyperautomation.com> ...

numeric ddw with leading zeroes; is it possible?
we have a drop down datawindow whose purpose is to display a social security number. the social security number is numeric in the database. the problem occurs when a number with leading zeroes is entered into the field; they are trimmed off. an editmask of "000000000" in the child datawindow works fine, but seems impossible to have a dropdown edit style and editmask edit style at the same time. we have a work around involving two columns sitting on top of each other; the column on top is an editmask, the one below is a dropdown with just the arrow visible behind the...

Converting numeric value to string with leading zeroes
Hi, We have a smallint column on a table in which we store ISO country numeric codes. These values range in length from 1 to 3 (when stored as smallint). However we now have a requirement that we output them to a flat file they must be of length 3 with leading zeroes if required e.g. 76 must be '076'. Obviously I could just do a few IF statements with DATALENGTH and STR but I was wondering if someone has a nice tidy way if doing it. Eoin > Obviously I could just do a few IF statements with DATALENGTH and STR but I > was wondering if someone has a nice tidy...

Dropping leading zeros in a GridView nvarchar field
I have a GridView that displays a column where the data is an "nvarchar" type.  These values are numbers, but look like this: "001", "002", "009", "010", "011". I would like to trim off the leading zeroes in the displayed GridView.  I have experimented with using a DataFormatString, but that is not working, as the values are not numbers - they are strings, essentially.  I know I could modify my database to store integers (as all of these values are in fact, numbers), but that brings up another problem.  I have &...

Excel taking off leading zeros in text field.
I am hoping someone can help me. I have some excel reports that I am creating on the fly using vb.net. I am displaying them into a datagrid. I pass a sql string in and then use the below code dgFinalReport.Visible = True dgFinalReport.DataBind() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("Content-Disposition", "inline;filename=test.xls") dgFinalReport.RenderControl(writer) My leading zeroes are then gone from all my text fields that have leading zeros......

What would be the easiest way to delete leading zeros from a numeric amount???
Hello all,I would like to hear any easy way of eliminating leading zeros from some values I got?for example I have have this variable which is defined as a stringDim varAmount as string note: "varAmount is equal to 000019000"I would like to convert that into 19000I tried Ctype(varAmount), IntegerAny other suggestions?thanks, Check out this tip from ASPNet101.com: http://aspnet101.com/aspnet101/tips.aspx?id=60David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple...

Re: [PATCH] Zero-padded Numerics in Perl Format
Matt Sergeant <matt@sergeant.org> wrote: > shouldn't formats be put in an external module anyway? They seem to have > no real purpose being a core function, and are broken in an embedded > environment anyway (see mod_perl, for example). I propose an external > format module that can also output to strings I have a paper on that in TPC4. Damian On Fri, 19 May 2000, Damian Conway wrote: > Matt Sergeant <matt@sergeant.org> wrote: > > > shouldn't formats be put in an external module anyway? They seem to have > ...

infragistics Web Numeric Edit Control
Hi All,I am using "infragistics Web Numeric Edit Control" in my web from.I want to save the leading Zeros which are entered in the textbox.eg: when 004567 is entered i wanted to save it as 004567 instead of 4567.any solution please let me know.Many thankswesley  The ASP.NET Forums are not available to provide free support for commercial components.Please visit the Infragistics website and, from the Resources menu on the left, click on the Support item. You should find the support you need with Intragistics' support options. Alister...

ASE text field to ASA text field
Hi I'm having problems populating an ASA text field with data from an ASE text field using CIS(component integration services) from ASE to link up to ASA. After running the SQL statement it appears to put NULLS in the ASA field. All other data types appear to work fine. I know you can use readtext/writetext to read/write text fields properly but it requires a size parameter. Any thoughts or suggestions would be appreciated. Here is the SQL I'm trying to run; insert asa_invt_prod_note select invt_prod_id,note_type,note,fpi_rep_status_flag,created_date,created_by,up...

Web resources about - Padding Numeric field with leading Zeros - sybase.ase.general

Optimal asymmetric encryption padding - Wikipedia, the free encyclopedia
and subsequently standardized in PKCS#1 v2 and RFC 2437 . The OAEP algorithm is a form of Feistel network which uses a pair of random oracles ...

Clintonworld is centre of pocket padding universe
Clinton nostalgia is being replaced by Clinton neuralgia.

MP sorry for padding his resume
State Liberal MP David Southwick apologises for misleading personal information on his website.

Former treasurer Peter Costello warns tax reform hard without 'padding' in public opinion, more difficult ...
Peter Costello warns the Government tax reform will be difficult and that it may not have the political capital to pull it off.

Padding and the Contractor
If padding hours is a problem in Biglaw, imagine what would happen if you paid lawyers by the hour.

Contractor Accuses LA Times of Padding Circulation Figures
In 2007, the U.S. Attorney’s office in Brooklyn announced it was ceasing prosecution of Tribune publications Newsday and Hoy for padding circulation ...

That's Not Padding, My Resume's Just Fat
That's Not Padding, My Resume's Just Fat

Recalls: 2013 Ford C-Max Hybrid recalled over lack of roof padding
Filed under: Hybrid , Minivan/Van , Wagon , Recalls , Safety , Ford Ford is recalling 33,021 units of its 2013 C-Max Hybrid not equipped with ...

The truth behind padding your CV
When looking for a job, every little bit counts — as long as it’s true.

Rams, Edward Jones Dome Cover Concrete with Padding After Reggie Bush's Injury - Bleacher Report
On the heels of injuries suffered by San Francisco 49ers running back Reggie Bush and Cleveland Browns quarterback Josh McCown at the Edward ...

Resources last updated: 11/27/2015 5:38:29 AM