Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Rounding Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: February 09 2009 at 22:05 | IP Logged Quote GadgetGuy

When I use a function like

Code:
round([LOCAL5],1)

I would expect it to always produce a single digit to the right of the decimal point.

Thus 32.57 would be 32.6 and 32.0 would be 32.0, but I'm finding that a whole number like 32.0 seems to produce a result of "32" without any decimals.

On my home web page where I am trying to present various temperatures, I would like them to all be consistent and not add/drop a digit to the right of the decimal.

what I am getting is . . .


But what I would like is for the 38 degree temp to be presented as 38.0, which the round does not seem to be doing.

The value appears in a Global var and is stored there as 38 even though I created it from data with the round() function.

Is there a way to always get one decimal digit?

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 09 2009 at 22:15 | IP Logged Quote dhoward

Of course, it's PowerHome .

Try:
Code:

string([LOCAL5],"#.0")


This will give you what you want including the actual rounding.

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: February 10 2009 at 10:51 | IP Logged Quote GadgetGuy

Dave thanks.

Actually please note, I wanted to do something like that but the Documentation, while continually talking about "Format CHaracters" never defines them anywhere I could discover.

I tried a number of things like "n.n" and "#.#" but never thought of the correct one.

This would be a good thing to make sure it gets documented somewhere.

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: February 10 2009 at 11:32 | IP Logged Quote GadgetGuy

A little Post Script.

While the above approach did gave me a Global value with single decimal precision, as I wanted, I was still getting an integer number on my web page whenever the temperature data readings were whole numbers (such as 2.0 for the Freezer)



To fix this last step I had to edit my HTML code for the web page and make the PH ASP calls. . .
Code:
<%string(ph_getglobal_n("TEMP-FREEZER"),"#.0")%>


That is, I had to add the string function here too, as the simplier getGlobal function returned an integer value.

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 10 2009 at 13:09 | IP Logged Quote dhoward

If the global already has the proper format with the trailing decimal, then you should also be able to just use:

<%ph_getglobal_s("TEMP-FREEZER")%>


Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: February 10 2009 at 13:43 | IP Logged Quote GadgetGuy

Dave - Ah So!

I just wrote a long Reply here telling you that was what I had done, and that it didn't work when I noticed I had been using getglobal_n not getglobal_s as you suggest.

So mea culpa. I deleted my long story and replace it with this humble "thanks." Your insight is quite valid.

Edited by GadgetGuy - February 10 2009 at 13:44


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum