1

I am writing a praat script to segment a file, but also add padded boundaries. When I use the following line:

start = 9.17
paddedStart = fixed$(start - 0.200, 3)

I get the error

"Found a string expression instead of a numeric expression"

but if I try

paddedStart = fixed$(number(start), 3)

I get the error

"The function "number" requires a string, not a number."

How can I used the fixed$ function to limit the number of decimal places in a number?

2
  • At the level of numeric computation, I don't think you can control Praat's precision by defining the limit on floating point. Your question is about converting a floating point number to a character string, as you figured out.
    – user6726
    Feb 24, 2019 at 0:39
  • 1
    I'm voting to close this question as off-topic because Praat questions may sometimes be linguistics-related but this one just seems like a general programming language question applied to specifically Praat.
    – LjL
    Feb 25, 2019 at 0:22

2 Answers 2

2

I figured it out. fixed$ creates a string, not a number. So, if you use the number function, a number is returned. Ex: number(fixed$(start - 0.200, 3))

1
  • 1
    Please mark your own answer as "accepted".
    – prash
    Mar 8, 2019 at 8:55
1

fixed$ takes only 2 arguments, so you should realise your calculations outside the function.

The variable start has only 2 digits after the decimal point, so it is meaningless to propose 3 digits.

Try this:


start = 9.17

start2 = start - 0.2

paddedStart = fixed$(start2, 1)

paddedStart2 = number(paddedStart)


2
  • Thanks, but I already tried this, and it didn't work. The problem is that fixed$ returns a string.
    – Lisa
    Feb 24, 2019 at 0:26
  • You just have to change your string in number by using the function number(): paddedStart2 = number(paddedStart).
    – amegnunsen
    Feb 24, 2019 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.