Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Monday, March 26, 2012

Formattting numbers

I would like to format the number 12345 into 12,345. How can I achieve this?

in C#:

int num = 1234567890;
String numFormatted = num.ToString("#,#");

Check out this documentation for more specifics on number formatting:

http://msdn2.microsoft.com/en-us/library/0c899ak8(VS.71).aspx

|||

I would like to acheive this in reporting services.

|||

I found out. I can make it using the format tab in properties of the textbox

Friday, March 23, 2012

Formatting numbers with commas in TSQL

Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?

Cheers
Dave"David Sharp" <dave@.daveandcaz.freeserve.co.uk> wrote in message
news:ca434844.0312150306.34760a0@.posting.google.co m...
> Once I've converted my floats to chars using STR, is there an easy way
> to put commas in separating the thousands.
> i.e. convert
> 53000000.12
> to
> 53,000,000.12
> I'm thinking I'll have to do it with a user defined function and the
> various string functions myself but was wondering if anyone had an
> easier way?

Yes, do it at your presentation layer, not at the DB layer.

> Cheers
> Dave|||Hi Dave

You shouldnt really do any formatting of numbers in the database. It
should be done on the client.

Sam

dave@.daveandcaz.freeserve.co.uk (David Sharp) wrote in message news:<ca434844.0312150306.34760a0@.posting.google.com>...
> Once I've converted my floats to chars using STR, is there an easy way
> to put commas in separating the thousands.
> i.e. convert
> 53000000.12
> to
> 53,000,000.12
> I'm thinking I'll have to do it with a user defined function and the
> various string functions myself but was wondering if anyone had an
> easier way?
> Cheers
> Dave|||dave@.daveandcaz.freeserve.co.uk (David Sharp) wrote in message news:<ca434844.0312150306.34760a0@.posting.google.com>...
> Once I've converted my floats to chars using STR, is there an easy way
> to put commas in separating the thousands.
> i.e. convert
> 53000000.12
> to
> 53,000,000.12
> I'm thinking I'll have to do it with a user defined function and the
> various string functions myself but was wondering if anyone had an
> easier way?
> Cheers
> Dave

You could do this TSQL by creating your own functions, but you should
probably do it in the front end application instead, if possible. The
format above is incorrect in Spain and Germany, for example - a client
application can retrieve locale information and format the output
accordingly much more easily than doing it on the server side.

Simon|||"David Sharp" <dave@.daveandcaz.freeserve.co.uk> wrote in message
news:ca434844.0312150306.34760a0@.posting.google.co m...
> Once I've converted my floats to chars using STR, is there an easy way
> to put commas in separating the thousands.
> i.e. convert
> 53000000.12
> to
> 53,000,000.12
> I'm thinking I'll have to do it with a user defined function and the
> various string functions myself but was wondering if anyone had an
> easier way?

IMHO, this is a job for the Presentation Layer/GUI. I wouldn't store commas,
or format the numbers for me. I'd rather handle this on the client side so I
am not storing needless data (, and .) in the database, and so I can format
the data properly according to regional setting on the client side.

--
BV.
WebPorgmaster - www.IHeartMyPond.com
Work at Home, Save the Environment - www.amothersdream.com|||> Once I've converted my floats to chars using STR, is there an easy way
> to put commas in separating the thousands.
> i.e. convert
> 53000000.12
> to
> 53,000,000.12
> I'm thinking I'll have to do it with a user defined function and the
> various string functions myself but was wondering if anyone had an
> easier way?
> Cheers
> Dave
Hi Dave,

If you really want to do it in TSQL. Cast as Money. Then convert
using style 1. "convert(varchar,cast(myVar as money),1)" - Louis|||Thanks to everyone who replied and of course who are absolutely
correct that this sort of data formatting should be done in a
presentation layer rather than the db.

Unfortunately in this specific case, the text is being generated to
annotate a simple calculation performed in a stored proc called by a
trigger and so doesn't have a presentation layer in which to do the
formatting.

Thanks Louis for highlighting a possible solution.

louisducnguyen@.hotmail.com (louis nguyen) wrote in message news:<b0e9d53.0312151608.7c1f93f2@.posting.google.com>...
> If you really want to do it in TSQL. Cast as Money. Then convert
> using style 1. "convert(varchar,cast(myVar as money),1)" - Louissql

Formatting numbers question

I have a datagrid with currency amounts, the default currency format "C" shows only two decimal places, I would like to show up to 4 decimal places. Useing the formula/expression editor, how would this be done?Have you tried C4? Currency with 4 numbers of precision. Just an thought, I do not know if it will work or not.|||

I do this in the expression.

=Format(Fields!ThisValue.Value, "$#.####)

Hope this helps.

|||

Both of the above are possible options.

rs12345 - put "c4" into the Format property of the textbox

guyinkalamazoo2 - apply the formatting directly tot he value in the expression of the textbox

Wednesday, March 21, 2012

Formatting numbers in SQL

Hi
I need to format the output of a numeric value from SQL-server with a
chosen thousand-separator and decimal-separator.
The Access equivalent would be something like:
Select format(myNumber, "#.###,##") as myFormattedNumber from myTable;
I have searched the net for a solution, and found something about
FORMAT_STRING, but that doesn't seem to be usable in SQL-Server...
Can anyone help me with this?
Regards,
Johnny Nordtvedt, NorwayIn an N-Tier environment it's better to leave presentational features
out of the database and do them in your client/middle tier. Some users
might prefer to configure a different numeric format so it's probably
not something you ought to fix in a SELECT statement.
TSQL does have a CONVERT function, which provides some limited
formatting capability but only if you convert your numerics to a
string. Also, AFAIK the CONVERT function only supports comma as a
thousands separator by default. In reality you should find it much
easier to do the formatting in the client control or form that displays
the data.
David Portas
SQL Server MVP
--|||My problem is that these values is displayed in a Word-document, and the
program that collects these values and inserts them into word, is not
available for formatting, and will not ever be available. So basically, I
am stuck with formatting this in SQL-server.
Regards,
Johnny Nordtvedt, Oslo, Norway|||Is it possible to make a user defined function to do this? And how would I
go by to do this?
Still hope that someone can help me with this. I am certain someone has
done this before?
Regards,
Johnny Nordtvedt, Oslo, Norway|||DECLARE @.numeric NUMERIC(10,2)
SET @.numeric = 123456.78
SELECT
REPLACE(REPLACE(REPLACE(
CONVERT(VARCHAR(10),CAST(@.numeric AS MONEY),1)
,',','~') ,'.',',') ,'~','.')
David Portas
SQL Server MVP
--|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
There are formatting functions on Merge fields in Word. Read the Word
Help file (in English version):
Field Types and Switches
Field Reference
Switches
How to: Highlight merge field, hit Alt-9. Add switches at end of
field:
/# will give numeric format.
/#.#,## I believe will format the number 99999.00 as 99.999,00
Also, read the Word Help articles on Merge Fields.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQlWjTIechKqOuFEgEQLidACfWKC4/ST6Pc1f6yJC3xaIoOO4dC8AoKLM
k5KfIvuctrzjBfvZduWw4W0t
=lpsE
--END PGP SIGNATURE--
Johnny, Norway wrote:
> My problem is that these values is displayed in a Word-document, and the
> program that collects these values and inserts them into word, is not
> available for formatting, and will not ever be available. So basically, I
> am stuck with formatting this in SQL-server.

formatting numbers in Crystal Reports

:confused:

Hello,

I need to format my numbers as follows:
In my ttx file I have a field called Quantity with a datatype of Number and the value that i used is 1.00
I need to know how to how to get the value of 1 and not 1.

I also have another line
Quantity number 1.500

and when i simply put that on the report, it prints the number 2. What am i doing wrong? This is what I have as code so far.

if int({tester.quantity2}) = {tester.quantity2} then
formula = totext({tester.quantity2}, "#####.#####")
else
formula = totext({tester.quantity2})
end if

Thanks
NadishaHi,

Try to set the format at design time. Right Click the formula/database field. Goto Format option, there you can find info about formatting under "Number" tab.

Formatting numbers in charts

Is there a property or hack that would allow for the numbers (for each
series) in a piechart to appear OUTSIDE the "pie" itself. In other words the
numbers displayed outside the series with lines or arrows pointing to the
corresponding "piece?"
the intent of course is to allow users to see the number when the series is
too small to fit the number inside the chart
thanks?"Outside" labels for pie and doughnut charts were added in RS 2000 SP1.
Check the Readme file of SP1 / SP2:
http://download.microsoft.com/download/5/1/3/513534ae-a0e7-44e6-9a04-ba3c549a5f5f/sp2Readme_EN.htm#_chart_enhancements
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"neokortex" <neokortex@.discussions.microsoft.com> wrote in message
news:C6F25E23-7719-41E7-9DFD-A103501D1AA6@.microsoft.com...
> Is there a property or hack that would allow for the numbers (for each
> series) in a piechart to appear OUTSIDE the "pie" itself. In other words
> the
> numbers displayed outside the series with lines or arrows pointing to the
> corresponding "piece?"
> the intent of course is to allow users to see the number when the series
> is
> too small to fit the number inside the chart
> thanks?|||This works by the way...although oddly the changes are not visible in the VS
IDE..only after it was uploaded to the server
thanks
"Robert Bruckner [MSFT]" wrote:
> "Outside" labels for pie and doughnut charts were added in RS 2000 SP1.
> Check the Readme file of SP1 / SP2:
> http://download.microsoft.com/download/5/1/3/513534ae-a0e7-44e6-9a04-ba3c549a5f5f/sp2Readme_EN.htm#_chart_enhancements
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "neokortex" <neokortex@.discussions.microsoft.com> wrote in message
> news:C6F25E23-7719-41E7-9DFD-A103501D1AA6@.microsoft.com...
> > Is there a property or hack that would allow for the numbers (for each
> > series) in a piechart to appear OUTSIDE the "pie" itself. In other words
> > the
> > numbers displayed outside the series with lines or arrows pointing to the
> > corresponding "piece?"
> >
> > the intent of course is to allow users to see the number when the series
> > is
> > too small to fit the number inside the chart
> >
> > thanks?
>
>|||Yes, outside labels are not shown at design time - only in preview or when
rendering on the server.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"neokortex" <neokortex@.discussions.microsoft.com> wrote in message
news:B7135406-41AD-4A8F-A161-B242C13EA033@.microsoft.com...
> This works by the way...although oddly the changes are not visible in the
> VS
> IDE..only after it was uploaded to the server
> thanks
> "Robert Bruckner [MSFT]" wrote:
>> "Outside" labels for pie and doughnut charts were added in RS 2000 SP1.
>> Check the Readme file of SP1 / SP2:
>> http://download.microsoft.com/download/5/1/3/513534ae-a0e7-44e6-9a04-ba3c549a5f5f/sp2Readme_EN.htm#_chart_enhancements
>> -- Robert
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> "neokortex" <neokortex@.discussions.microsoft.com> wrote in message
>> news:C6F25E23-7719-41E7-9DFD-A103501D1AA6@.microsoft.com...
>> > Is there a property or hack that would allow for the numbers (for each
>> > series) in a piechart to appear OUTSIDE the "pie" itself. In other
>> > words
>> > the
>> > numbers displayed outside the series with lines or arrows pointing to
>> > the
>> > corresponding "piece?"
>> >
>> > the intent of course is to allow users to see the number when the
>> > series
>> > is
>> > too small to fit the number inside the chart
>> >
>> > thanks?
>>

Formatting Numbers in an SQL Statement

Hi,
I have a table that has an ID field which is automatically incremented as each new record is added, so if I do a SELECT * FROM Table1 I get:
ID, Name
1, Billy
2, Bob
3, Tony
You get the idea. What I want to do is format the number differently when it's returned from an SQL statement so I get:
ID, Name
0001, Billy
0002, Bob
0003, Tony
So I need something like SELECT FORMATNUMBER(ID, 4), Name FROM Table1 - Does anything like this exist?
Little 'un.This type of functionality is probably better served in your code, rather than on Sql. Sql is rather slow at doing string functions.
SELECT
RIGHT( '0000' + cast( ID as varchar), 4 ) ID
FROM
table1
bill|||

Hi Bill,

Thanks for that, unfortunately it's not something I can do in my ASP code, so that should work a treat.

Little'un

sql

Formatting numbers

I have a column in a dataset and i would like to change the number format of the column so that it has comma's separating the thousands place.

Hi,

Function Fixbigint(lng as long) as string
Dim nfi As System.Globalization.NumberFormatInfo = _
New System.Globalization.CultureInfo _
("en-US", False).NumberFormat
' lng=9223372036854775807
nfi.NumberGroupSeparator =","
return lng.ToString("N", nfi)
end function

s it any useful.

kiki


|||

Is that for Sql.

|||

NVM i figured it out again.Sleep

formatting numbers

I am using a MS Access ADP connected to SQL Server Data

In a view I have the following formula:

dbo.tblQuoteItem.Cost + dbo.tblQuoteItem.Markup * dbo.tblQuoteItem.Cost * .01

this calculates cost + markup

I cannot get it to format in Currency

Ex:

Cost is $1.75
Markup is 2.00 (2%)
Total shows - 1.785000

I want $1.78

Also - I am using this formula to calculate the Quoted price for the Qty Entered

dbo.tblQuoteItem.Qty * dbo.tblQuoteItem.Cost + dbo.tblQuoteItem.Markup * dbo.tblQuoteItem.Cost * .01

Using a Qty of 2 for above, I get 3.535000

I want $3.53

Any help is appreciated - ABSQL Server does not format output. That is the job of your interface (Access ADP, in this case).

Set the format of your form control or report field to display as currency.|||you could something like SELECT CAST(3.5553 as decimal(10,2)) but this rounds up (3.56). I would handle this in your VBA with a formatcurrency('your variable here',2).

This might round too. Or it might just cut off your percision. I forget. Test.

Formatting numbers

Any help on this problem would be greatly appreciated.
I have a field in my database that contanis numbers (i.e. 1, 2, 6, 7
etc.)
I want to create a stored procedure to return these numbers, but
formatted in such a way that they always show a full 10 digits. For
example 7 would be 0000000007 and 243 would be 0000000243 and 120000007
would be 0120000007 etc.
I know in Access something like this could be achieved by doing
format$([MyNumber],"0000000000"). Anyone know how I can do this in SQL?
-JoelSELECT RIGHT('0000000000' + CAST(YourNumberCol AS VARCHAR(10)),10)
Andrew J. Kelly SQL MVP
<jsnation@.gmail.com> wrote in message
news:1133567995.941523.96000@.f14g2000cwb.googlegroups.com...
> Any help on this problem would be greatly appreciated.
> I have a field in my database that contanis numbers (i.e. 1, 2, 6, 7
> etc.)
> I want to create a stored procedure to return these numbers, but
> formatted in such a way that they always show a full 10 digits. For
> example 7 would be 0000000007 and 243 would be 0000000243 and 120000007
> would be 0120000007 etc.
> I know in Access something like this could be achieved by doing
> format$([MyNumber],"0000000000"). Anyone know how I can do this in SQL?
> -Joel
>|||Formatting should be done in your frontend not in SQLServer, but you
could consider this one here:
DECLARE @.Number VARCHAR(10)
SET @.Number = 2
SELECT RIGHT('0000000000' + @.Number,10)
HTH, Jens Suessmeyer.|||DECLARE @.temp TABLE ( test_number INT IDENTITY )
DECLARE @.i INT
SET NOCOUNT ON
SET @.i = 1
-- Insert some dummy values
WHILE @.i < 100
BEGIN
INSERT INTO @.temp DEFAULT VALUES
SET @.i = @.i + 1
END
SET NOCOUNT OFF
SELECT REPLICATE ( 0 , 10-LEN( test_number ) ) + CAST( test_number AS
VARCHAR )
FROM @.temp
-- Damien
"jsnation@.gmail.com" wrote:

> Any help on this problem would be greatly appreciated.
> I have a field in my database that contanis numbers (i.e. 1, 2, 6, 7
> etc.)
> I want to create a stored procedure to return these numbers, but
> formatted in such a way that they always show a full 10 digits. For
> example 7 would be 0000000007 and 243 would be 0000000243 and 120000007
> would be 0120000007 etc.
> I know in Access something like this could be achieved by doing
> format$([MyNumber],"0000000000"). Anyone know how I can do this in SQL?
> -Joel
>|||>> have a field [sic] in my database ..<<
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files.
The basic principle of a tiered architecture is that display is done in
the front end and never in the back end. This a more basic programming
principle than just SQL and RDBMS.
You are asking BAAAAAD questions from fundamental ignorance. Please
get a few eyars under your belt before you try to write a database.
Remember, it takes SIX years to become a Union Journeyman Carpenter
(NOT a Master!) in New York State. How long have you been writing SQL?|||Wrong! Formatting (display) is done where it is most efficient and scalable
to do it. We aren't using mainframes anymore, it matters how much data is
passed between the server and client/middle tier.
The most basic programming principle is that you look at your architecture
and design for what you have and not implement definitive statements likes
yours willy nilly.
Consider - paging, pivoting etc... is it really efficient to pass back a
million rows to the client just to get the second page of 50 rows? Nope, it
isn't - but thats what your statement proposes.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1133666034.583452.191970@.g43g2000cwa.googlegroups.com...
> Let's get back to the basics of an RDBMS. Rows are not records; fields
> are not columns; tables are not files.
>
> The basic principle of a tiered architecture is that display is done in
> the front end and never in the back end. This a more basic programming
> principle than just SQL and RDBMS.
> You are asking BAAAAAD questions from fundamental ignorance. Please
> get a few eyars under your belt before you try to write a database.
> Remember, it takes SIX years to become a Union Journeyman Carpenter
> (NOT a Master!) in New York State. How long have you been writing SQL?
>|||Hi
I think, most efficient way will be
Select Replace(Str(m, n), ' ', '0')
Where m is actual number and n is required length
e.g. Select Replace(Str(8, 10), ' ', '0')
will return 0000000008
Prashant Deshmukh
"jsnation@.gmail.com" wrote:

> Any help on this problem would be greatly appreciated.
> I have a field in my database that contanis numbers (i.e. 1, 2, 6, 7
> etc.)
> I want to create a stored procedure to return these numbers, but
> formatted in such a way that they always show a full 10 digits. For
> example 7 would be 0000000007 and 243 would be 0000000243 and 120000007
> would be 0120000007 etc.
> I know in Access something like this could be achieved by doing
> format$([MyNumber],"0000000000"). Anyone know how I can do this in SQL?
> -Joel
>sql

formatting numbers

Hi,
I was wondering whether there is a way to format numbers in sql as below.
Meaning I was to convert 1 to 0001 (with maximum of 4 as the length)
So that 100 = 0100, 0999, 0022, 1222, etc...
Does anyone know how to do this?
Thanks
DhruvTry:
declare @.x int
set @.x = 121
select right('0000' + cast(@.x as varchar(4)), 4) num
set @.x = 100
select right('0000' + cast(@.x as varchar(4)), 4) num
set @.x = 999
select right('0000' + cast(@.x as varchar(4)), 4) num
- Vishal|||Try this:
declare @.i smallint
set @.i = 23 -- or ...
select RIGHT('000' + CAST(@.i AS varchar(4)), 4)
HTH
Vern
>--Original Message--
>Hi,
>I was wondering whether there is a way to format numbers
in sql as below.
>Meaning I was to convert 1 to 0001 (with maximum of 4 as
the length)
>So that 100 = 0100, 0999, 0022, 1222, etc...
>Does anyone know how to do this?
>Thanks
>Dhruv
>.
>|||You could do soemthing like this in T-SQL:
declare @.i int
set @.i = 122
select right('0000' + cast(@.i as varchar(4)), 4)
But I'd question why you'd want to do this on SQL Server
side? This is best done at the clietn side in whatever
language you may be using. Most languages have good
support for this type of string manipulation.
Linchi
>--Original Message--
>Hi,
>I was wondering whether there is a way to format numbers
in sql as below.
>Meaning I was to convert 1 to 0001 (with maximum of 4 as
the length)
>So that 100 = 0100, 0999, 0022, 1222, etc...
>Does anyone know how to do this?
>Thanks
>Dhruv
>.
>|||SELECT RIGHT('0000'+RTRIM(1), 4)
However, I agree with Linchi. Do your "prettifying" of the data where it
belongs, in the presentation tier.
> I was wondering whether there is a way to format numbers in sql as below.
> Meaning I was to convert 1 to 0001 (with maximum of 4 as the length)
> So that 100 = 0100, 0999, 0022, 1222, etc...
> Does anyone know how to do this?
> Thanks
> Dhruv|||I don't know that I completely agree with that, though I see the point.
Consider the case where you use the same data 10 places, using the same
stored procedure. The formatting would be easier done in the procedure,
rather than the UI.
--
----
--
Louis Davidson (drsql@.hotmail.com)
Compass Technology Management
Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266
Note: Please reply to the newsgroups only unless you are
interested in consulting services. All other replies will be ignored :)
"Aaron Bertrand - MVP" <aaron@.TRASHaspfaq.com> wrote in message
news:%23GXS0IrjDHA.2312@.TK2MSFTNGP12.phx.gbl...
> SELECT RIGHT('0000'+RTRIM(1), 4)
>
> However, I agree with Linchi. Do your "prettifying" of the data where it
> belongs, in the presentation tier.
>
> > I was wondering whether there is a way to format numbers in sql as
below.
> >
> > Meaning I was to convert 1 to 0001 (with maximum of 4 as the length)
> >
> > So that 100 = 0100, 0999, 0022, 1222, etc...
> >
> > Does anyone know how to do this?
> >
> > Thanks
> >
> > Dhruv
>|||> Consider the case where you use the same data 10 places, using the same
> stored procedure.
In most client applications, you can have a common formatting routine.|||Awesome
Thanks
"Vishal Parkar" <_vgparkar@.yahoo.co.in> wrote in message news:<#LU2$ArjDHA.744@.tk2msftngp13.phx.gbl>...
> Try:
> declare @.x int
> set @.x = 121
> select right('0000' + cast(@.x as varchar(4)), 4) num
> set @.x = 100
> select right('0000' + cast(@.x as varchar(4)), 4) num
> set @.x = 999
> select right('0000' + cast(@.x as varchar(4)), 4) num

Formatting Numbers

I am using the following format to display a percentage: ##.##%;(##.##%);"-"
It works fine for numbers like 15.34% but when the percent is a whole number
like 4% it does not display 4.00%. Can anyone help me with this format?
Thanks in Advance
OS##0.00%
"OriginalStealth" <OriginalStealth@.discussions.microsoft.com> wrote in
message news:6D66A65C-2566-4DCC-8244-7E377ADF3954@.microsoft.com...
>I am using the following format to display a percentage:
>##.##%;(##.##%);"-"
> It works fine for numbers like 15.34% but when the percent is a whole
> number
> like 4% it does not display 4.00%. Can anyone help me with this format?
> Thanks in Advance
> OS

Formatting numbers

Hi all,
I would like to know how can one change the thousand and decimal separator.
I tried to change the ReportingServer web.configs <globalization> culture
and uiCulture.
Regardless of the cultures I am always getting US number formats (e.g.
"1,234,567.89").
The format string I use on the report is: "#,##0.00" and according to the
cultures I would expect to get "1.234.567,89".
Please help I am already desperateOn the 'Report' properties there is a Language setting - you need to set
that.
--
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||Hi Tony,
Thanx I missed that property - it works now!!!!
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:efviupE2EHA.3840@.tk2msftngp13.phx.gbl...
> On the 'Report' properties there is a Language setting - you need to set
> that.
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>

Formatting negative numbers without space between minus sign and number

How can I format these numbers without a space between the minus sign
and the number. I use the following "Format" for my numbers:
# ### ### ### (and have also tested to add ;-# ### ### ###) without
success!
-90000000.12345 formats to - 90 000 000 when I would like to have -90
000 000 Numbers like -1 should also be accpted... -1 instead of - 1...
Is there an easier whay to format this number? And how can I remove
the space...
Thank youI tried working with your example and several variations on the ### format
string. The space between the "-" and the value seems to built-in to that
format string. Please see the following for additional ideas:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformattingoverview.asp
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andreas Kardell" <akardell@.home.se> wrote in message
news:67424f9d.0410130707.1e79c943@.posting.google.com...
> How can I format these numbers without a space between the minus sign
> and the number. I use the following "Format" for my numbers:
> # ### ### ### (and have also tested to add ;-# ### ### ###) without
> success!
> -90000000.12345 formats to - 90 000 000 when I would like to have -90
> 000 000 Numbers like -1 should also be accpted... -1 instead of - 1...
> Is there an easier whay to format this number? And how can I remove
> the space...
> Thank you|||Hi Andreas
I found the following format worked in some instances ie for numbers 999 or
999999 etc.
=iif(Fields!ActualQty.Value < 0, "# ###"," # ###")
I too am having fun with conditional formating at the moment.
Fiona
"Bruce Johnson [MSFT]" wrote:
> I tried working with your example and several variations on the ### format
> string. The space between the "-" and the value seems to built-in to that
> format string. Please see the following for additional ideas:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformattingoverview.asp
>
> --
> Bruce Johnson [MSFT]
> Microsoft SQL Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Andreas Kardell" <akardell@.home.se> wrote in message
> news:67424f9d.0410130707.1e79c943@.posting.google.com...
> > How can I format these numbers without a space between the minus sign
> > and the number. I use the following "Format" for my numbers:
> > # ### ### ### (and have also tested to add ;-# ### ### ###) without
> > success!
> >
> > -90000000.12345 formats to - 90 000 000 when I would like to have -90
> > 000 000 Numbers like -1 should also be accpted... -1 instead of - 1...
> >
> > Is there an easier whay to format this number? And how can I remove
> > the space...
> >
> > Thank you
>
>|||Thank you Bruce!
I'm not too familiar with .NET Framework yet so I solved it by putting
the following code into the value field instead and leaving the format
field empty:
=IIF(Fields!fQuantity.Value < 0, "-", "") +
Ltrim(Format(Abs(Fields!fQuantity.Value), "# ### ### ###"))
I'm not too happy about this workaround but I use it for now.
Thanks a lot
"Bruce Johnson [MSFT]" <brucejoh@.online.microsoft.com> wrote in message news:<ulD7npUsEHA.3324@.TK2MSFTNGP15.phx.gbl>...
> I tried working with your example and several variations on the ### format
> string. The space between the "-" and the value seems to built-in to that
> format string. Please see the following for additional ideas:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformattingoverview.asp
>
> --
> Bruce Johnson [MSFT]
> Microsoft SQL Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Andreas Kardell" <akardell@.home.se> wrote in message
> news:67424f9d.0410130707.1e79c943@.posting.google.com...
> > How can I format these numbers without a space between the minus sign
> > and the number. I use the following "Format" for my numbers:
> > # ### ### ### (and have also tested to add ;-# ### ### ###) without
> > success!
> >
> > -90000000.12345 formats to - 90 000 000 when I would like to have -90
> > 000 000 Numbers like -1 should also be accpted... -1 instead of - 1...
> >
> > Is there an easier whay to format this number? And how can I remove
> > the space...
> >
> > Thank you|||Well, I don't have the same experience.
I am using SP1, but you are probably using that too.
Here's the format string I use in the format property of the TextBox.
#,#;-#,#;0
If you need to use it in code, the syntax would be:
String.Format("{0:#,#;-#,#;0}", Field.Value)
The result is just what you say you are wanting.
BTW, if it still does not work I suggest using CUSTOM CODE (look it up
in the help) to standardize/centralize the code you use to do the
formatting.
BR//Jerry|||#,#;-#,#;0

formatting issues for excel

hi,

I have a column of numbers which export fine to excel when i use the formatting '$0'.

If any of the values in the column = 0 i dont want them to show so i added this line to the value =iif(Fields!Budget.Value = 0, "", Fields!Budget.Value). This works fine except when i export to excel it now doesnt read them as values and you have to convert all the cells individually. I guess this is becuase i have substituted the string "" when the data = 0 and excel does the formatting for the whole column not each cell individually. What should i do so it exports to excel correctly? Is there another way to show nothing in a cell and it still registers as a number?

geoff

WHat about Nothing rather than "" ?

=iif(Fields!Budget.Value = 0, Nothing, Fields!Budget.Value).

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Monday, March 19, 2012

Formatting Currency Numbers from Analaysis Services

Hi,

I'm using Reporting Services in conjunction with Analysis Services.

The problem I'm having is formatting numbers to be dollar amounts. I know how to set this in Reporting Services and when a data source was regular SQL, then everything was just fine. However, when I switch to Analysis Services the number would just stay the same.
i.e. "60.2" instead of "$60.20". The only thing I can think of is if Analysis Services is returning the number as a string for some reason, and RS won't format strings for currency.

Any thoughts? Thanks!You should be able to format measures from SSAS the same way you do this with a relational database. Can you repro your issue with the Adventure Works cube?|||I think this is the problem: the numbers that being returned are attributes not measures... which is right b/c I'm using the numbers as parameters for drill-down reports.

So the question is how do you format a number returned by AS20005 as an attribute to be a U.S. dollar amount? Thanks!|||Okay, looks like the attribute number was getting returned as a string. I used CDbl() to convert into a double and it works fine now.

Monday, March 12, 2012

FormatNumber >> Excel export?

Hi all

I want my measures to be exported(Excel) as numbers instead of text.
When i simply use them as is it does this correct but as soon
as I as the following number formating it no longer exports
correctley.

=FormatNumber(Fields!Example.Value,2,True,True,True)

The same apllies to whe I set the formatting in the text box properties to N

Can some please tell me how I can acheive this result when exporting

Thanks in advance

G

Apply formatting using N in the Format property, then in the value textbox, apply an explicit cast of the value. E.g.

=CDbl(Fields!Example.Value)

Bizzare, but I've found this to work for me.

|||

Thanks Adam

I came accros the same thing today when i was casting
the values returned from custom code. I just hope the same
principal will aplly to currency.

In my case I had to figure to use N0
as format type to get 1,345,456

When using the cdbl() to do this you cant use FormatNumber(,,,)
that was my snag.

Thanks again for your time

G

Formating Numbers with Commas

I am pulling numbers from a SQl Table and adding some together and
doing other calculations. How do your format the numbers to insert a
comma and show thousands?Display formatting is always done In the front end, of course This is
the basic idea of a tiered architecture, which is more fundamental than
just SQL.

Formating Numbers with Commas

I am pulling several numbers from a SQL table, adding them and doing
various calculaitons. The numbers do not display a comma to separate
thousands. What is a way to format this?Presentation and formatting are usually done in the client, not the
server. In this case, for example, many countries do not use a comma
for separating thousands, so your client application can check the
user's locale and apply the correct formatting.

Simon|||There's no easy way to do this. For some reason I did need output like
this and wasn't able to use a front end to do the formatting, so I made
my own function.

Use as so:

SELECT dbo.Format_Number(513434512.2344)

Output is $513,434,512.23

Yes, it rounds and adds a dollar sign. But you can change it around.
:)

HTH,
Jennifer

CREATE FUNCTION Format_Number (@.N decimal(18,2))
RETURNS nVarChar(30)

AS

BEGIN

Declare @.NRnd Decimal(18,2)
Declare @.Dollar nVarChar(30)
Declare @.Dollar2 nVarChar(30)
Declare @.L int
Declare @.A int
Declare @.B int
Declare @.C int
Declare @.Cents nvarchar(20)
Declare @.NC nvarchar(30)

Set @.NC = Cast(@.N as Nvarchar(30))

Set @.NRnd = Round(@.N, 0, 1)
Set @.Dollar2 = ''
Set @.Dollar = Cast(@.NRnd as NvarChar(30))
Set @.Dollar = Substring(@.Dollar,1, Len(@.Dollar) - 3)

Set @.C = PATINDEX('%.%',@.NC)
Set @.Cents = Substring(@.NC, @.C, 3)
Set @.L = Len(@.Dollar)
Set @.A = @.L/3

Set @.B = 3
While @.A >= 0
Begin
Set @.Dollar2 = Substring(@.Dollar,@.L - @.B + 1,3) + ',' + @.Dollar2
Set @.B = @.B + 3
Set @.A = @.A - 1
End
If Left(@.Dollar2,1) = ','
Set @.Dollar2 = Substring(@.Dollar2, 2, Len(@.Dollar2))

Return '$' + Substring(@.Dollar2,1, Len(@.Dollar2)-1) + @.Cents
END|||>> For some reason I did need output like this and wasn't able to use a
front end to do the formatting, so I made my own function. <<

Since this is a fundamental violation of software engineering
prtinciples, might you share with us WHAT that reason was? It is worth
a paper in a journal.|||It was a totally stupid reason, of course. :) My boss wanted an email
output of a query emailed to him on a daily basis, so I set up a job to
do that. And then he came back and said, it sure would be nice if
those dollar amounts looked like dollars, and could the output be
changed. So being completely new and straight out of school I did as
asked.

Let me know how that paper comes out, will you? ;)|||--CELKO-- (jcelko212@.earthlink.net) writes:
> Since this is a fundamental violation of software engineering
> prtinciples, might you share with us WHAT that reason was? It is worth
> a paper in a journal.

The world is not always as ideal as you may want to be. There are probably
tons of business reports out there that are run from no other front end
than Query Analyzer, or similar tool. For some reason, someone started to
do it in QA, probably because it was a little urgent, and not possible to
pack into something better. Then that temporary hack became permaent etc.
Until one day, the requirements goes beyond what is really healthy to do
in SQL.

Anoher reason could be that the front-end tool is hopelessly difficult
to use...

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Formating numbers in SSIS

I have a Amount field which is declared as Decimal. the data for this will be somethin like this 0.152

output need it to be -

00000.1520

How can I do this?

You'll have to convert it a string and prepend/append the zeroes.

-Jamie

|||Thank You. I converted the field into string and prepended the zero's. but it was too many steps. i wish SSIS had some kind of format function available to do this.|||

Godai B wrote:

Thank You. I converted the field into string and prepended the zero's. but it was too many steps. i wish SSIS had some kind of format function available to do this.

Too many steps? Really?

"0000" + (DT_STR, 20, 1252) 0.1520

That doesn't seem like too many to me. Can you give me examples of format functions like you require?

-Jamie

|||

this field is derived from 2 columns in a sql server table and the datatype is decimal(18,3)

the output format needs to be 000000.0000 .

the input field can have a single digit or upto six digits before the decimal point. if it has a single digit then i need to prepend "00000", if there are 2 digits then i prepend "0000" and so on.

same with digits after the decimal point.

ex: Input -->10.120 Output --> 000010.1200

Input --> .1 Output --> 000000.1000

what i did was, used the findstring function in the derived column to find the decimal point position and then got the predecimal digits and postdecimal digits. then with the help of length function i prepended or appended the zero's and then finally concatenated the predecimal and postdecimal digits.

Hope u can help me with an easy way to do this.

|||

I would use the FINDSTRING function as you have done to get the whole and the mantissa. But instead of using LENGTH I would just do this:

RIGHT("000000" + [wholepart], 6) + "." + REVERSE(RIGHT(REVERSE([mantissapart] + "0000"), 4))

Yeah, maybe a format function would be good.

-Jamie