The code at the end of the email reads in a string with a length of 2
items. As shown below the string is two numbers with three decimal
places.

String passed to JESS is 2.000 2.100

But trailing zeros are removed as shown in the output from the explode$
Function

Found a Max Min Value condition(2.0 2.1)

In this case the number of decimal places is important and I try later
to find how many places in the original to set the format of the output.
Is this a normal behavior? If so what can I do to preserve the number of
decimal places.

Thanks
Jeff Ruff
ChipData

The Code:

;Rule for maxValue minValue
;Rule for maxValue minValue
(defrule maxMinEntry
(string ?str)
(Length ?len &:(= ?len 2))
=>
   (if (str-index , ?str)
   then
      ;We must substitue the comma for a period
      ;(printout t "Modified value is " (call ?str replace "," ".")
crlf)
      (bind ?modString (call ?str replace "," "."))
   else
      ;Wed need to do nothing
      (bind ?modString ?str)
   )

   (printout t "String passed to JESS is " ?modString crlf)
   (printout t "Found a Max Min Value condition" (explode$ ?modString)
crlf)
   (bind ?maxValue (max$ (explode$ ?modString)))
   (bind ?minValue (min$ (explode$ ?modString)))
   (printout t "Max Value " ?maxValue  " Min Value " ?minValue crlf)

   ;Find the decimal place to use
   (bind ?last (sub-string (+ (str-index . ?minValue) 1) (str-length
?minValue) ?minValue))
   (bind ?decimalMin (str-length ?last))

   (bind ?last (sub-string (+ (str-index . ?maxValue) 1) (str-length
?maxValue) ?maxValue))
   (bind ?decimalMax (str-length ?last))
   (bind ?decimalPlace (max ?decimalMin ?decimalMax))
   ;(printout t "Using decimal place value of " ?decimalPlace crlf)

   (bind ?tol (format nil (str-cat "%." ?decimalPlace "f") ( / (-
?maxValue ?minValue) 2)))
   (bind ?value (format nil (str-cat "%." ?decimalPlace "f") (+
?minValue ?tol)))
   ;(printout t "Nominal value is " ?value " Tolerance is " ?tol crlf)
   (store datasheetValue ?value)
   (store datasheetTol ?tol)
)

(deffunction funcall (?fnc $?args)
   (eval (format nil "(%s %s)" ?fnc (implode$ ?args)))
)

(deffunction max$ (?1)
   (funcall max ?1)
)

(deffunction min$ (?1)
   (funcall min ?1)
)

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to