陈亚娣 发表于 2014-3-20 11:01:38

请教,非四舍五入法 个人难题

请教各位老师,有个人难题就是我想将小数点第一个的数值小于5时将数值改为小数位数值等于5,小数点第一个的数值大于5时向整数进一~
例如(xxx 1.5 1.5);;xxx表示为函数名,当数值为1.5 变为1.5
       (xxx 1.4 1.5);;xxx表示为函数名 ,当数值为1.4 变为1.5
       (xxx 1.3 1.5);;xxx表示为函数名 ,当数值为1.3 变为1.5
       (xxx 1.2 1.5);;xxx表示为函数名 ,当数值为1.2变为1.5
       (xxx 1.1 1.5);;xxx表示为函数名 ,当数值为1.1 变为1.5

       (xxx 1.6 2.0);;xxx表示为函数名 ,当数值为1.6 变为2.0
       (xxx 1.7 2.0);;xxx表示为函数名 ,当数值为1.7 变为2.0
       (xxx 1.8 2.0);;xxx表示为函数名 ,当数值为1.8变为2.0
       (xxx 1.9 2.0);;xxx表示为函数名 ,当数值为1.9变为2.0

cable2004 发表于 2014-3-20 11:01:39

(Defun XXX(a)
(if (equal (fix (+ 0.4999999 a)) (fix a) 0.0001)
   (+ 0.5 (fix a))(fix (+ 0.5 a))
))

yaokui25 发表于 2014-3-20 11:14:42

开心版主的文字替换程序,一直在用
会对你有帮助的
;替换文字
; (KX-reptext 选择集 <要找的文字> <替换成的文字>)
(defun KX-reptext (SS oldch newch / ss ssl ct0 edata etext txtln subln ct1 ct2 schct newtext)
   (if ss
   (progn
       (setq ssl (sslength ss)
             ct0 0
             ct1 0
             ct2 0
             subln (strlen oldch)
       )
       (while (< ct0 ssl)
         (setq edata (entget (ssname ss ct0))
               etext (cdr (assoc 1 edata))
               txtln (strlen etext)
               schct 1
               newtext ""
         )
         (while (<= schct txtln)
         (setq newtext
             (strcat newtext
               (if (= (setq readch (substr etext schct subln)) oldch)
               (setq ct1 (1+ ct1)
                   schct (+ schct subln)
                   newch newch
               )
               (progn
                   (setq schct (1+ schct))
                   (substr readch 1 1)
               )
               )
             )
         )
         )
         (if (/= etext newtext)
    (progn
             (entmod (subst (cons 1 newtext) (assoc 1 edata) edata))
             (setq ct2 (1+ ct2))
         )
         )
         (setq ct0 (1+ ct0))
       )
   )
   )
)

(DEFUN C:XX()
   (setvar "cmdecho" 0)
(setq ss(SSGET":s" '((0 . "*TEXT"))) )
   (KX-reptext SS "A" "1")
   (KX-reptext SS "B" "2")
   (KX-reptext SS "C" "3")
   (KX-reptext SS "D" "4")
(PRINC)
)

lgttblue 发表于 2014-3-20 11:20:30

自贡黄明儒 发表于 2014-3-20 11:41:25

(defun xxx (x1 x2)
(* (FIX(/ (+ x1 0.5) x2)) X2)
)

陈亚娣 发表于 2014-3-20 11:47:37

自贡黄明儒 发表于 2014-3-20 11:41 static/image/common/back.gif


谢谢黄总的回答~
页: [1]
查看完整版本: 请教,非四舍五入法 个人难题