Rounding (up/down) to a certain number of decimal places

Hello Group

How do I round say 1.23 up/down to 2 decimal places? I am currently
(ab)using [format].

Thanks
Evilson
0
Evil
10/16/2010 8:45:41 AM
comp.lang.tcl 22570 articles. 0 followers. Post Follow

3 Replies
1316 Views

Similar Articles

[PageSpeed] 36
Evil Son <ewilsonmail@gmail.com> writes:

> How do I round say 1.23 up/down to 2 decimal places? I am currently
> (ab)using [format].

Sounds like the right choice.

-- 
Donald Arseneau                          asnd@triumf.ca
0
Donald
10/16/2010 10:24:21 AM
On 16 Pa=C5=BA, 10:45, Evil Son <ewilsonm...@gmail.com> wrote:
> Hello Group
>
> How do I round say 1.23 up/down to 2 decimal places? I am currently
> (ab)using [format].

Using [format] is completly correct way, but if you prefer to avoid it
for some reason, there is other way:

set precision 2
set roundedValue [expr { double(round($value * pow(10,$precision))) /
pow(10,$precision) }]

Regards,
Googie
0
10/16/2010 2:08:44 PM
On Oct 17, 12:08=C2=A0am, Googie <pawelsal...@gmail.com> wrote:
> On 16 Pa=C5=BA, 10:45, Evil Son <ewilsonm...@gmail.com> wrote:
>
> > Hello Group
>
> > How do I round say 1.23 up/down to 2 decimal places? I am currently
> > (ab)using [format].
>
> Using [format] is completly correct way, but if you prefer to avoid it
> for some reason, there is other way:
>
> set precision 2
> set roundedValue [expr { double(round($value * pow(10,$precision))) /
> pow(10,$precision) }]
>
> Regards,
> Googie

Thanks Donald and Googie ... least of all for figuring out what I
meant. My example should have been 1.234 :P
Yes [format] works fine on my machine but I was just wondering about
whether it would behave the same on other machines and whether that
was the correct way to do it. Sounds like it is. (IIRC, C's <stdio.h>
printf's behaviour is undefined here. But this is Tcl of course ...
and my C is rusty.)

Thanks again.
Evilson
0
10/16/2010 4:10:40 PM
Reply:
Similar Artilces:

US-TX-Round Rock: RN Stepdown.Telemetry 7a-, Graduation from a NLN accredited sc (45355957612)
US-TX-Round Rock: RN Stepdown.Telemetry 7a-, Graduation from a NLN accredited sc (45355957612) ============================================================================================== Position: RN Stepdown.Telemetry 7a- Reference: CAM00023 Location: Round Rock TX Duration: PERM Skills: Graduation from a NLN accredited school of nursing. 3-5 years experience supervision in ptient care. Experience conducting initial and ongoing assessment of the patient and family, development of a family centered patient care pla...

output SAS data with a field of 16-digit number into an excel
Since excel only allows 15 digit (for double precision) be presented, how should I convert the field consisting of 16-digit number (say account number) be fully shown in my excel spreadsheet automatically? Much appreciated for any hints. XL ...

how do deal with huge numbers and keep them accurate?
Hello all, I wrote the following code: require "bigdecimal" require "bigdecimal/math" include BigMath odd = gets.chomp.to_f result = odd/3.0 puts result.to_f blank = gets.chomp the code works just fine when the input is upto 15 digits, but afterwards the code fails to give the correct output. a few good examples: odd=1231231 result=410410.333333333 odd=123123123123121 (15 digits) result=41041041041040.3 so far so good,now: odd=1231231231231231 (16 digits) result=4.1041041041041e+014 (given with no remainder) [It's a wrong answer! the result should have ...

Filemaker 6, Serial number and ODBC
Hi all, I'm inserting a record via ODBC into filemaker and the table has a AutoEnter Serial that can't be modified. After I do the insert, I'd like to find out what the serial number was assigned to, so that I can continue working with it (or insert related rows). In SQL Server I have @@IDENTITY, anything similar for filemaker? Thanks Andy ...

AMD vs. Intel: Some hard numbers
I have been developing on an AMD system: Win2K SP3 AMD XP 1900+ Motherboard: MSI low end ($65 board) 3 7200 rpm Maxtor 40GB IDE drives 2 512 MB PC2100 Samsung CAS latency = 2 I just built a new Intel system for development: Win2K SP 4 Intel P4 3.0C (hyper threaded 3GHz) Motherboard: Gigabyte GA-8KNXP (Hottest 875P MB on the planet per Hardocp.com) 1 WD 80 MB 7200 rpm IDE for booting 2 WD 36GB 10,000rpm SATA drives in a RAID 0 array 2 512MB PC3200 Corsair Twinex dual channel 2-2-2-6 (The really high end and really really expensive stuff.) Performance comparison: I simply used one of my larg...

US-TX-Round Rock Director of Women's Servi, 3-5 years of Healthcare Management (45354832410)
US-TX-Round Rock Director of Women's Servi, 3-5 years of Healthcare Management (45354832410) ============================================================================================= Position: Director of Women's Services Reference: CAM00005 Location: Round Rock, TX Duration: Perm Skills: 3-5 years of Healthcare Management is required. Must have a Bachelor degree in area of expertise or equilivant experience. Current Texas Registered Nurse License. Certification in basic cardiopulmonary resusciation required for working in clinal/patient care area. ...

Not a number problem
In my code I used NAN and isnan(x). I found they were convenient to use. I also noticed that older C standard does not support NAN and isnan(x). When I compiled my program using: gcc -Wall -c it was fine. But when I compiled my program using: gcc -Wall -ansi -pedantic -c it reported some errors, reporting NAN and isnan(x) not supported. I knew the options -ansi and -pedantic make things conform to the older C standard (C90?). My question are: 1. Is it fine to compile my program using "gcc -Wall -c" instead of using the more conservative "gcc -Wall -ansi -pedantic -c...

rounding FP to u significant digits
While REPRESENT provides for the creation of a string representation of a floating point number to a specified number of significant digits, there are some situations in which it is necessary to round an fp number to a fixed number of significant digits. These situations are probably rare, but I ran into one recently for the numerical solutions of eigenvectors. An word for rounding fp numbers to a specified number of significant digits is given below. Perhaps this can be shortened? KM -- \ Round fp value to u significant digits variable power \ Return power of ten factor which scales f su...

Credit card number rounding?
I am trying to print a contract for a customer specifying use of their credit card number. For some odd reason the number is being rounded. I checked - it's a text field. On the other hand, I format it as: CCNO: Format([CCNum],"0000-0000-0000-0000") The last two digits get rounded e.g. 36 becoms 40 etc. I believe it's being coerced into a numeric field before it's being formatted, and the numeric field can't support the number of significant digits you require. You may have to use String functions: CCNO: Left([CCNum], 4] & "-" & Mid([CCNum], ...

Two VAXBI Node number plugs needed
I need two of the little blue node number plugs that go on a BI backplane. I could use any two of the numbers 3, 9, 10, 14, or 15. Does anybody have any extras that they'd be willing to sell, trade, barter, lend, give, lease, ... ?? Thanks much, Bob Armstrong bob@jfcl.com Bob Armstrong wrote: > ... Alternatively, does anybody know the part number for these plugs, so I can see if any are still available ? Thanks, Bob On 8 Jun 2006 06:22:42 -0700, "Bob Armstrong" <bob@jfcl.com> wrote: > >Bob Armstrong wrote: >> ... > > Alternatively, does ...

How to draw rectangles with rounded corner ?
Hello, I want to draw rectangles with rounded corners. I know the command 'setlinejoin' but I can't give it the radius. Do you know something which could help me ? thanks :) -- yves piel yvespiel <yvespielusenet@free.fr> wrote: >Hello, >I want to draw rectangles with rounded corners. I know the command >'setlinejoin' but I can't give it the radius. >Do you know something which could help me ? There is no command to do it directly. You will need to combine drawing straight lines and drawing arcs. ---------------------------------------- Aandi Inst...

rounding
Hi, I am attempting to round a number (float) to 2 decimal digits in java. How is this possible? Thanks, -- Adrien Martel cs2 One approach would be to multiply the number by 100, cast it to an int, then divide it by 100.0. This would truncate instead of round. > I am attempting to round a number (float) to 2 decimal digits in java. How > is this possible? http://www.xdweb.net/~dibblego/java/faq/answers.html#q28 -- Tony Morris http://xdweb.net/~dibblego/ <klynn47@comcast.net> schreef in bericht news:1103571572.279608.114830@c13g2000cwb.googlegroups.com... > One ap...

Rounding (COBOL and otherwise)
As a follow-up to the other "threads" on ROUNDING, I have posted a page that is an (edited) version of a paper discussed by J4 in 1993 on "rounding" and some other possible (and existing in other languages and software) approaches. Thank you to Jordan Wouk for providing his original paper to me. The edited online version may be viewed at: http://home.comcast.net/~wmklein/DOX/RNDG.htm It should be noted that even as the 2002 Standard was revised and delayed, it was felt that there was insufficient "user-demand" to extend (much less modify) the existing (tr...

sorting polynomials by the degree of certain terms
Hi, I dealing with huge polynomials (around 50,000 terms). Each term may contain some real coefficient, followed by any combination of 11 variables, each of which may be raised to some some power. However, I'm interested in sorting the polynomial according to the sum of the degrees of only 2 of the variables. In other words, in the sorted expression, the first terms would be those where the two variables do not appear (the sum of their powers is zero). The next terms would be the terms where one of the two variables appeared raised to the power 1. The next terms would be the ter...

Re: minimum number of values #2
raz <razina_ta@YAHOO.COM> wrote: > I would like to know the minimum no of values need to plot a > boxplot. Is it possible to draw the boxplot with a data set of 3 > numbers? say 13,15,16 ? Let me second the excellent advice of Peter and Dale. There is simply no *point* in drawing a boxplot when you have so few points that you can plot all the points instead. A boxplot is an exploratory data approach to handle the case where there are more data points than can be visualized. Unless you have discrete values which pile up on top of one another, you can simply plot the individ...

reading file round and round
Hi There, I read out the content from a file like: foreach $line (<$handle>) { print $line; sleep(1); } whixh works well so far. But what I would like is, if the loop gets to eof, it should start over on top again. How can i reset the reading pointer back to the beginning of the file? Thanks, -- roN On Mar 19, 11:43=A0am, cerr <ron.egg...@gmail.com> wrote: > Hi There, > > I read out the content from a file like: > foreach $line (<$handle>) { > =A0 =A0 =A0 =A0 =A0 print $line; > =A0 =A0 =A0 =A0 =A0 sleep(1); > =A0 =A0 ...

Aereo Loses First Round in Copyright Office, While Dish Wins its Next Round in the Ninth Circuit [telecom]
By Herry Cole, CommLawBlog, July 20, 2014 More developments in the realm of Internet retransmission of OTA signals. Aereo - the gift that keeps on giving, at least when it comes to blogworthy content. As we reported, after it got its clock cleaned at the Supreme Court, Aereo bounced back with Plan B, which amounted to declaring itself (a) a cable system and, thus, (b) eligible for the compulsory copyright license granted to cable systems. But you can't just say "I'm a cable system" and expect anybody to believe you. So Aereo went ahead with some of the paperwork re...

Manual numbering with special characters
I'm writing a mostly expository piece of text and I'd like to "number" one or two of the involved equations with a special character instead of a number. Is there an easy way to do this? Thanks and regards, Travis -- To reply, please remove "123." from my username (one dot should remain). "Travis Willse" <travis.willse@gmail.com> wrote in message news:17ydndG22crMLPnfRVn-sw@comcast.com... > I'm writing a mostly expository piece of text and I'd like to "number" > one or two of the involved equations with a special chara...

Please enter a real or fractional number.
Hello, I have sometimes problems with plotting. The problem starts when I use the command plot. When I want to change anything in the plot dialogbox, the message dialogbox: "Please enter a real or fractional number." appears.The problem seems to be that I get comma's and that should be points in the Plot dialogbox. Anyone familiar with this problem? Running W2K Dutch, AutoCAD 2000 English. Thanks, Maick Klaassen, Quality Engineering & Consulting info@qec.nl www.qec.nl This used to be a problem with drivers to HP plotters. Try using the windows drive...

US-TX-Round Rock: ER Nurse (RN), Current TX liscense as an RN. Previous experie (45355032401)
US-TX-Round Rock: ER Nurse (RN), Current TX liscense as an RN. Previous experie (45355032401) ============================================================================================== Position: ER Nurse (RN) Reference: CAM00015 Location: Round Rock TX Duration: Perm Skills: Current TX liscense as an RN. Previous experience in clinical nursing preferred. Certification in basic cardiopulmonary resuscitation. Computer skills. 2 years of emergency room nursing experience. Scope: ER Nurse is responsible f...

Identify number of n
Hello I would like to compute the following new=(x-w)/n the n (i.e. number of observations) is different for each id/year combination. Which is the easiest way to identify the number of observations for each id/year combination? Thank you. On Oct 12, 7:00=A0pm, treser...@GOOGLEMAIL.COM wrote: > Hello > > I would like to compute the following > > new=3D(x-w)/n > > the n (i.e. number of observations) is different for each id/year > combination. Which is the easiest way to identify the number of > observations for each id/year combination? > > Thank you. If ...

New Market Place for Zul'jin server
chek out the new market place for Zul'jin server, and plz tell me if there's allready place to do that. http://groups-beta.google.com/=ADgroup/WOWMarket Trade and sells for cash or Gold and save on your AH Fees, all on Zul'jin Server. ...

how to convert string into number
Hi all, I read several rows of numbers and split each row into an array. I get an array of array. By default Ruby treat each number as a string. I want to convert each string into a number. The only way I can think of is to loop through the old array of array, change each element in each row using #to_f and put them back into a new array. It is not efficient. What other options might be better? Thanks, Li # file format 1 100 33 32 2 500 33 20 .... -- Posted via http://www.ruby-forum.com/. Hi, i would do it like this: array = [] yourfile.each_line{|line| array << line.split...

How to verify if a string contains valid decimal data
Hi all, I have some strings that I need to convert to fixed decimal(p, q). The strings all have type char(100), but p and q will vary based on different fields in the record. Before assigning the strings to fixed decimal(p, q) variables I would like to validate that they are in a proper format, to give som nice error messages if they are not. I know I could let the compiler handle this for me, but that gives warnings in the compiler listing and makes it impossible to give nice error messages. Therefor I cooked up the following function to validate if a string can be converted to a fixed dec...

Whats your logic behind your part numbers and drawing Numbers
For some reason they don't have any system for part numbers at my work and I want to start using them. How do you guys create your part numbers/drawing numbers? Do you have any kind of logic behind your part numbers? When naming your parts do you save the file name as the part number or a Name(description)? Which way do you prefer? "Nathan Feculak" <nfeculak@goawyspam_namco.ca> wrote in message news:KQvTb.7158$7O2.5794@edtnps89... > For some reason they don't have any system for part numbers at my work and I > want to start using them. How do you guys create y...