Re: [Gimp-user] does number->string have format options?

great thanks!

I am looking for the programmers reference / documentation for the scheme interpreter included with gimp. I have so far not found it, and other scheme interpreters seem to have many different definitions for eg string parsing functions. Do you know where the documentation such as a list of all functions can be found?


On 05/01/2012 07:41 AM, Rob Antonishen wrote:

does number->string have format options? What is the equivalent of "printf" in gimp tinyscheme?

I am scripting adding axes to an image and need to control of format of floating point numbers that will be passed to gimps text generation functions.

Here is a helper function I had written to deal with this:

(define (number->fixedstring V D)
  (let ((D (trunc D)))
      (number->string (if (> D 0) (trunc V) (round V)))
      (if (> D 0) (string-append "." (number->string (round (* (- V (trunc V)) (pow 10 (trunc D)))))) "")

In use, the first parameter is the value and the second is the number of decimals to include.  It rounds to the decimal specified and pads where zeros if needed.

> (number->fixedstring 3.14159 0)
> (number->fixedstring 3.14159 1)
> (number->fixedstring 3.14159 2)
> (number->fixedstring 3.14159 3)
> (number->fixedstring 3.14159 4)
> (number->fixedstring 3.14159 5)
> (number->fixedstring 3.14159 6)
> (number->fixedstring 2.7 0)

-Rob A>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]