Re: does number->string have format options?

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




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?

Burlen

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)))
    (string-append
      (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)
"3"
> (number->fixedstring 3.14159 1)
"3.1"
> (number->fixedstring 3.14159 2)
"3.14"
> (number->fixedstring 3.14159 3)
"3.142"
> (number->fixedstring 3.14159 4)
"3.1416"
> (number->fixedstring 3.14159 5)
"3.14159"
> (number->fixedstring 3.14159 6)
"3.141590"
> (number->fixedstring 2.7 0)
"3"


-Rob A>

_______________________________________________
gimp-user-list mailing list
gimp-user-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gimp-user-list

[Gimp Announce]     [Gimp Images]     [GIMP Development]     [Video For Linux]     [Photo]     [Yosemite News]    [Yosemite Photos]    [gtk]     [KDE]     [Scanner]     [Gimp's Home]     [Gimp Docs]     [Gimp on Windows]     [Steve's Art]     [Webcams]     [Share Your Images]     [Free Online Dating]     [Photo Site]     [Script Fu]     [GIMP Software]     [GIMP Books]

Barnes&Noble.com

Add to Google Follow Gimp on Twitter