Author Topic: Forcing Decimal Places  (Read 6093 times)

0 Members and 1 Guest are viewing this topic.

hendie

  • Guest
Forcing Decimal Places
« on: March 22, 2007, 07:50:36 AM »
It's been a while since I had to program in Lisp (and it's really really showing  :cry:)

this is doin' ma heid in mon.....
I am adding a list of numbers and I cannot get the result to show with 2 decimal places.

my UNITS is set to Decimal
PRECISION is set to 4
UNITMODE is 0 (tried it with 1 as well)

Code: [Select]
(setq X 17.00)
17.0
_$ (setq Z (rtos X 2 2))
"17"

what is the blatantly obvious bit that I'm missing ? please enlighten me oh great Lispers

CADaver

  • Guest
Re: Forcing Decimal Places
« Reply #1 on: March 22, 2007, 07:56:54 AM »
Check UNITMODE
or
Try setting DIMZIN to 0


Found the following in Developer Help:
Quote
AutoLISP function rtos returns incorrect value (no zeros after decimal separator)
--------------------------------------------------------------------------------
Issue
You use the AutoLISP® function rtos to return a string representing the settings of the mode and precision for the units in the drawing. This string must be a whole number expressed with zeros after the decimal separator. However, the function seems to return an incorrect value. For example:
(setq z 100)
(rtos z 2 2))

You expect (rtos z 2 2)) to return 100.00, but sometimes the value returned is displayed as 100.

Solution
The AutoLISP function rtos takes information from four system variables: UNITMODE, DIMZIN, LUNITS and LUPREC. Usually, an incorrect value returned by rtos is caused by the DIMZIN variable being set to a value other than 4,3,2,1, or 0.

To resolve the problem, ensure that the DIMZIN variable is not set to 8 or 12.

The following information is from Help in the AutoCAD® software:
DIMZIN

Controls the suppression of zeros in the primary unit value. DIMZIN stores this value when you enter it on the command line or set it under Primary Units in the Annotation dialog box. DIMZIN values 0-3 affect feet-and-inch dimensions only.

0 Suppresses zero feet and precisely zero inches
1 Includes zero feet and precisely zero inches
2 Includes zero feet and suppresses zero inches
3 Includes zero inches and suppresses zero feet
4 Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)
8 Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)
12 Suppresses both leading and trailing zeros (for ex-ample, 0.5000 becomes 0.5)
« Last Edit: March 22, 2007, 08:00:08 AM by CADaver »

hendie

  • Guest
Re: Forcing Decimal Places
« Reply #2 on: March 22, 2007, 08:22:08 AM »
Thanks Alan, it was DIMZIN that did it

much appreciated

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Forcing Decimal Places
« Reply #3 on: March 22, 2007, 08:27:49 AM »
interesting ... I never knew that .. I must remember to start checking dimzin in those pesky little lisp routines .. ;)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Re: Forcing Decimal Places
« Reply #4 on: March 22, 2007, 08:55:36 AM »
hmm... :-o...I didn't know Randy changed his name to Alan...

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Forcing Decimal Places
« Reply #5 on: March 22, 2007, 09:03:55 AM »
DOH! .... Hendie must get his eyes checked ;)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Maverick®

  • Seagull
  • Posts: 14778
Re: Forcing Decimal Places
« Reply #6 on: March 22, 2007, 09:28:15 AM »
  Or he thinks Alan is a Cadaver.  :-o

hendie

  • Guest
Re: Forcing Decimal Places
« Reply #7 on: March 22, 2007, 09:37:14 AM »
Ooops, my sincere apologies Randy, I thought it was CAB that responded.... ooh the shame

Thanks RANDY !!!

CADaver

  • Guest
Re: Forcing Decimal Places
« Reply #8 on: March 22, 2007, 12:26:47 PM »
Ooops, my sincere apologies Randy, I thought it was CAB that responded.... ooh the shame

Thanks RANDY !!!
You're quite welcome.

BTW, Alan is one of the nicer things I've ever been called...

... especially around here.

hendie

  • Guest
Re: Forcing Decimal Places
« Reply #9 on: March 22, 2007, 03:15:31 PM »
Randy, in my opinion, you are intelligent enough, respected enough, and creditable enough to be called an "Alan" ~  we're a very exclusive club ya know

CADaver

  • Guest
Re: Forcing Decimal Places
« Reply #10 on: March 23, 2007, 12:36:36 AM »
Randy, in my opinion, you are intelligent enough, respected enough, and creditable enough to be called an "Alan" ~  we're a very exclusive club ya know
Thank you sir... I think. :)

For two years the music minister at church called me Jerry for some unknown reason, even though he had known me for years.  At first we'd all poke fun at him, but after a while I just answered to it.  Half the church still thinks my name is Jerry.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Forcing Decimal Places
« Reply #11 on: March 26, 2007, 01:55:57 PM »
Hendie / Alan is one of the Good guys too.

I would have answered but was out of town.
So better late than never.
Code: [Select]
;;  Pad.lsp    CAB 07/13/06
;;  Pad right with 0 to precision plc
;;  No Rounding!
(defun pad (str plc / sp)
  (setq tmp (reverse (vl-string->list str)))
  (if (not (vl-position 46 tmp))
    (setq tmp (cons 46 tmp))
  )
  (cond
    ((= (vl-position 46 tmp) plc))
    ((< (vl-position 46 tmp) plc)
     (repeat (- plc (vl-position 46 tmp))
       (setq tmp (cons 48 tmp))
     )
    )
    (t
     (repeat (- (vl-position 46 tmp) plc)
       (setq tmp (cdr tmp))
     )
    )
  )
  (vl-list->string (reverse tmp))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.