Notifications
Clear all

[Closed] number decimals to a text string ?

hey guys,
is it possible to display decimals from a float correctly in a text-shape ?

say i get the float values from a point.pos.controller and i have to ‘print’ it on-the-fly into a text_shape.text as string with the correct decimal (dots).


  	theNode = text name:"text_counter" font:"Arial Black Normal" size:20 wirecolor:yellow 
  	thePoint = point name:("pt_" + theNode.name) cross:false box:true size:40 axistripod:false centermarker:false wirecolor:green
  
  	FS = float_script()
  	FS.addNode "point" thePoint
  	FS.addNode "text_shape" theNode
  	FS.setExpression "
  		at time (f)
  		(
  		valOne = thePoint.pos.controller[1].value
  		valTwo = thePoint.pos.controller[3].value
  		text_shape.text = (valOne * valTwo) as string
  		0
  		)
  	"
  	theNode.leading.controller = FS
  	
  	ModEx = Extrude amount:2
  	AddMod = addModifier theNode (ModEx)
  

i need something like :

1
10
100
10.000
100.000
1.000.000

any tips ?

thanks in advance

5 Replies

Look at FormattedPrint in MXS help.

FormattedPrint[left]”[Flags][Width][.Precision][SizePrefix]Type”
[/left]
[left]where
[/left]
[left]Flags is:
[/left]
[left]Flag
[/left]
[left]Meaning
[/left]
[left]
[/left]
[left]Left align the result within the given field width. Default is to right align.
[/left]
[left]+
[/left]
[left]Prefix the output value with a sign (+ or -). Default is that sign appears only for negative signed values (-).
[/left]
[left]0
[/left]
[left]If width is prefixed with 0, zeros are added until the minimum width is reached. If 0 and – appear, the 0 is ignored. If 0 is specified with an integer format (i, u, x, X, o, d) the 0 is ignored. Default is no padding.
[/left]
[left]Blank (’ ‘)
[/left]
[left]Prefix the output value with a blank if the output value is signed and positive; the blank is ignored if both the blank and + flags appear. Default is no blank appears.
[/left]
[left]#
[/left]
[left]When used with the o, x, or X format, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively. Default is no blank appears. When used with the e, E, or f format, the # flag forces the output value to contain a decimal point in all cases. Default is decimal point appears only if digits follow it. When used with the g or G format, the # flag forces the output value to contain a decimal point in all cases and prevents the truncation of trailing zeros. Default is decimal point appears only if digits follow it, and trailing zeros are truncated. Ignored when used with d, i, or u.
[/left]

thanks for the info denisT, but i´m still lost…


at time (f)
(
 valOne = thePoint.pos.controller[1].value
 valTwo = thePoint.pos.controller[3].value
 str = formattedPrint (valOne * valTwo) format:".3f"
 text_shape.text = str
 0
)

yah,
thanks a lot guys.

now it´s working !