Welcome, Guest
  • Page:
  • 1

TOPIC: Formatting number inside a formula

Formatting number inside a formula 07 Jan 2007 05:54 #1619

  • DavidZ
  • OFFLINE
  • Platinum Boarder
  • Posts: 703
  • Karma: 4
I have a number from a field in the db that is used inside a formula. The resulting formula is text but the problem is that the number comes out with decimals which I do not want. If I was inserting the number directly onto the report I would decide the format of the number but how do I do it when I am using it from within a formula?

David
David Zeidman
Zeidman Development
www.zeidman.info

Check out our blog - www.re-decoded.com

Formatting number inside a formula 07 Jan 2007 05:54 #14056

  • DavidZ
  • OFFLINE
  • Platinum Boarder
  • Posts: 703
  • Karma: 4
I have a number from a field in the db that is used inside a formula. The resulting formula is text but the problem is that the number comes out with decimals which I do not want. If I was inserting the number directly onto the report I would decide the format of the number but how do I do it when I am using it from within a formula?

David
David Zeidman
Zeidman Development
www.zeidman.info

Check out our blog - www.re-decoded.com

Formatting number inside a formula 08 Jan 2007 05:00 #14059

  • DrewAllen
  • OFFLINE
  • Platinum Boarder
  • Posts: 1379
  • Karma: 1
Both ToText() and CStr() have optional parameters for format strings. You'll need to specify this in your formula. You'll probably want to use "#" or "#,###" depending on whether you want commas. If you use the second one, you may also want to trim off leading spaces.


Drew
J. Drew Allen

Crystal Reports and SQL Server Consultant




It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.

Formatting number inside a formula 08 Jan 2007 12:26 #14079

  • Doug Creek
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Karma: 0
or

toText( <number>, 0, "," )

The 0 represents decimal places, the "," represents the delimiter. Does this not work in 8?
~~~~~~~~~~~~~~~~~~~
Doug Creek
Systems and Reports Administrator
University of Alaska Foundation
This e-mail address is being protected from spambots. You need JavaScript enabled to view it ( This e-mail address is being protected from spambots. You need JavaScript enabled to view it )

Formatting number inside a formula 09 Jan 2007 03:30 #14088

  • DrewAllen
  • OFFLINE
  • Platinum Boarder
  • Posts: 1379
  • Karma: 1
Doug wrote:
or

toText( <number>, 0, "," )

The 0 represents decimal places, the "," represents the delimiter. Does this not work in 8?


That's what I get for replying too quickly. Yes, that formula works. The thousands separator is optional, so I'm assuming that you can just use
CStr(<number>,0)
and it will use the default separator defined for your computer. I haven't tested this, though, so it may just not use any separator.

Drew
J. Drew Allen

Crystal Reports and SQL Server Consultant




It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.

  • Page:
  • 1
Time to create page: 0.49 seconds