Re: Procedure for percent of a value



On 29 Feb., 16:35, Neil Madden <n...@xxxxxxxxxxxxx> wrote:
proc percent {num total} {
     expr {double($num)/double($total) * 100}
}

Also, you might have cases where the total is 0. I usually use

proc % {num den} {
if {$den == 0} {return --.---%}
format %.3f%% [expr {$num * 100. / $den}]
}
which returns a string with trailing %, filled with minuses when den
was 0.
.



Relevant Pages

  • Re: RtlAppendUnicodeStringToString
    ... of memory used for the string without the trailing 0. ... And the same seems to hold for the 'MaximumLength' member, ... now PathNameLength is as long as the directory string part ...
    (comp.lang.c)
  • Re: Parsing challenge to reduce blanks
    ... > therefor there are a BUNCH of trailing blanks presented to ... of the result as being the same length as the input string). ... you get no trailing blanks at all. ... following statement to pad with nulls: ...
    (comp.lang.fortran)
  • :) Contest: fast way to chop string in short fixed pieces.
    ... I am searching for _the_ tcl way to chop a given string into short ... chunks of a fixed length. ... If You don't know Your parameters beforehand, ... proc chop_string { ...
    (comp.lang.tcl)
  • Re: pass large blocks of data
    ...    I am trying to pass a large string  to a proc as an arg. ... when I see this arg value inside ... the proc, it was sliced and only 64 characters were there in the arg. ... I think it is due to the limitation of bash. ...
    (comp.lang.tcl)
  • Re: Remove trailing comments exercise
    ... slicing off part of it into an independent exercise ... For the rambunctious: remove trailing empty statements, ... So for this task it seems necessary to identify the string literals ... Tokenising the source was already implied in the task of verifying the ...
    (comp.lang.javascript)