Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   format for decimal values (http://www.velocityreviews.com/forums/t619227-format-for-decimal-values.html)

Nariban Barkan 06-09-2008 07:50 AM

format for decimal values
 
Hi All,

I have a decimal value on the GridView BoundField which comes from sql
server and it seems on gridview like that;
2096.62
14899.01

I want to display that values like
2.096,62
14.899,01

Thanks for any help



Pavel Minaev 06-09-2008 08:28 AM

Re: format for decimal values
 
On Jun 9, 11:50 am, "Nariban Barkan" <SomeFunny...@s.com> wrote:
> Hi All,
>
> I have a decimal value on the GridView BoundField which comes from sql
> server and it seems on gridview like that;
> 2096.62
> 14899.01
>
> I want to display that values like
> 2.096,62
> 14.899,01
>
> Thanks for any help


If you want to use locale-dependent group separator and decimal point,
then you need the "N" format specifier.

Mihai N. 06-09-2008 08:30 AM

Re: format for decimal values
 
> I have a decimal value on the GridView BoundField which comes from sql
> server and it seems on gridview like that;
> 2096.62
> 14899.01
>
> I want to display that values like
> 2.096,62
> 14.899,01



Convert to a double with Parse (or TryParse), then use ToString("N")
(or ToString("N",culture) if you want a culture other than the current one)



--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

Nariban Barkan 06-09-2008 08:50 AM

Re: format for decimal values
 
Thanks all..

and can i add a special tag or a custom currency mark after or before the
value on the BoundField column ?





siccolo 06-09-2008 03:42 PM

Re: format for decimal values
 
On Jun 9, 4:50*am, "Nariban Barkan" <SomeFunny...@s.com> wrote:
> Thanks all..
>
> and can i add a special tag or a custom currency mark after or before the
> value on the BoundField column ?


...or you can do format it in your sql server procedure... --> for
example see :
http://www.siccolo.com/Articles/SQLS...-currency.html

I know that not everyone is fond of formatting on sql server side, but
it's just a suggestion...


... more at http://www.siccolo.com/articles.asp

Pavel Minaev 06-10-2008 12:48 PM

Re: format for decimal values
 
On Jun 9, 12:50 pm, "Nariban Barkan" <SomeFunny...@s.com> wrote:
> Thanks all..
>
> and can i add a special tag or a custom currency mark after or before the
> value on the BoundField column ?


Then you need custom number format such as "#,##0.00'tag'" (note the
single quotes around 'tag' - they will ensure it is treated as a
literal string).
That's for CellFormatting event, though. For CellParsing, which you'll
also need for full two-way data binding, you'll probably want to trim
the tag/mark with String.Substring first, and then run it through
Decimal.Parse.

In general, I'd recommend searching MSDN for "Custom Numeric Format
Strings". It has more detailed explanations of what you can do with
this, and how.

Mihai N. 06-11-2008 06:18 AM

Re: format for decimal values
 
> Then you need custom number format such as "#,##0.00'tag'" (note the
> single quotes around 'tag' - they will ensure it is treated as a
> literal string).


Proper locale-aware formatting is done by setting
NumberFormatInfo.CurrencySymbol and using ToString("C", ...)
A currency format is not just a number format with currency attached to it
(even in US -123 migh be represented as (123) when it's about financial
stuff)



--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

Pavel Minaev 06-11-2008 01:04 PM

Re: format for decimal values
 
On Jun 11, 10:18 am, "Mihai N." <nmihai_year_2...@yahoo.com> wrote:
> > Then you need custom number format such as "#,##0.00'tag'" (note the
> > single quotes around 'tag' - they will ensure it is treated as a
> > literal string).

>
> Proper locale-aware formatting is done by setting
> NumberFormatInfo.CurrencySymbol and using ToString("C", ...)
> A currency format is not just a number format with currency attached to it
> (even in US -123 migh be represented as (123) when it's about financial
> stuff)
>
> --
> Mihai Nita [Microsoft MVP, Visual C++]http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email


That's assuming the original question was about locale-specific
currency formatting. However, the request was about "special tag or a
custom currency mark" - which, as I understand it, assumes that it is
not locale-dependent (and, indeed, may not be a currency sign at all,
merely something similar).


All times are GMT. The time now is 01:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.