Reducing the number of decimal places in a variable...
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 15
- Joined: Thu Aug 30, 2012 2:42 pm
- Location: United States
- Contact:
Reducing the number of decimal places in a variable...
I am trying to change a variable so that it only displays a maximum of 7 decimal places in a variable. as stands right now there are 13+ decimal places showing. I know I can count the number of digits in the string but if there are more or less numbers before the decimal places that will change how many it removes right?
If I delete everything after 10 digits for example...
10.987648915346 would become 10.9876489
but if the number were...
110.987648915346 then this would be the result 110.987648
Does this all make since?
Thanks in advance for the help.
If I delete everything after 10 digits for example...
10.987648915346 would become 10.9876489
but if the number were...
110.987648915346 then this would be the result 110.987648
Does this all make since?
Thanks in advance for the help.
Code: Select all
Let>NumVal=10.987648915346
VBSTART
VBEND
VBEval>FormatNumber(%NumVal%,7),FormatResult
MDL>FormatResult
-
- Newbie
- Posts: 15
- Joined: Thu Aug 30, 2012 2:42 pm
- Location: United States
- Contact:
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You don't actually need the vbstart and vbend blocks in the latest version.
The VBEval means "Evaluate this vbscript expression". Since it's a buit-in vbscript function there's nothing to declare inside the vbstart/vbend. You don't need those lines.
The VBEval means "Evaluate this vbscript expression". Since it's a buit-in vbscript function there's nothing to declare inside the vbstart/vbend. You don't need those lines.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 15
- Joined: Thu Aug 30, 2012 2:42 pm
- Location: United States
- Contact:
Thanks for the help guys. When I first tried this it worked like a champ. However now I am trying to use it today and its giving me a "vbscript runtimes are not properly installed". I have tried un-installing macro scheduler and the restarting and reinstalling to no avail. I also tried installing from microsoft the sp6 VB runtimes again and still no luck. Any thoughts? I am trying to use some of these values in a dialog box and its chopping off the numbers. Below is a sample of my code. You will see the call near the bottom.
AddDialogHandler>Excelo,buttonCalculate,OnClick,CalcVal
SRT>CalcVal
GetDialogProperty>Excelo,jobSheets,Text,jobShts
GetDialogProperty>Excelo,sheetSize,Text,sheetSz
GetDialogProperty>Excelo,totalUnits,Text,ttlUnits
GetDialogProperty>Excelo,sheetCutSec,Text,sheetCutSec
GetDialogProperty>Excelo,sheetItems,Text,shtItems
GetDialogProperty>Excelo,sheetPunchedSec,Text,shtPunchedSec
GetDialogProperty>Excelo,sheetK,Text,shtK
GetDialogProperty>Excelo,sheetC,Text,shtC
GetDialogProperty>Excelo,sheetM,Text,shtM
GetDialogProperty>Excelo,sheetY,Text,shtY
GetDialogProperty>Excelo,selectedPrinter,Text,Prntr
GetDialogProperty>Excelo,totalFeet,Caption,ttlFeet
GetDialogProperty>Excelo,totalPunchTime,Caption,ttlPunchTime
GetDialogProperty>Excelo,scrapQuantity,Caption,scrapQTY
GetDialogProperty>Excelo,FPP,Caption,feetPP
GetDialogProperty>Excelo,PM,Caption,peicesPM
//Calculate Total Feet
Let>ttlFeet={(%sheetSz%/12)*%jobShts%}
//Calculate Total Pieces
Let>actPrinted=%shtItems%*%jobShts%
//Calculate Pieces / Min.
Let>ttlPPM={%actPrinted%/(%ttlFeet%*%Prntr%)}
//Calculate Ink Usages
Let>ttlInkK=shtK/ttlUnits
Let>ttlInkC=shtC/ttlUnits
Let>ttlInkM=shtM/ttlUnits
Let>ttlInkY=shtY/ttlUnits
Let>ttlInkUsed=shtK
Add>ttlInkUsed,shtC
Add>ttlInkUsed,shtM
Add>ttlInkUsed,shtY
//Calculate Total Punch Time
Let>shtPunchedSec={%shtPunchedSec%*(%jobShts%/60)}
//Calculate Scrap Quantity
Let>scrapQTY=%actPrinted%-%ttlUnits%
//Calculate Feet Per Peice
Let>feetPP=%ttlFeet%/%actPrinted%
//Calculate Total Punch Time
//Let>shtPunchedSec={%shtPunchedSec%*(%jobShts%/60)}
SetDialogProperty>Excelo,totalFeet,Caption,%ttlFeet%
SetDialogProperty>Excelo,actualPrinted,Caption,%actPrinted%
SetDialogProperty>Excelo,PPM,Caption,%ttlPPM%
SetDialogProperty>Excelo,unitK,Caption,%ttlInkK%
SetDialogProperty>Excelo,unitM,Caption,%ttlInkM%
SetDialogProperty>Excelo,unitC,Caption,%ttlInkC%
SetDialogProperty>Excelo,unitY,Caption,%ttlInkY%
SetDialogProperty>Excelo,totalInk,Caption,%ttlInkUsed%
SetDialogProperty>Excelo,totalPunchTime,Caption,%ttlPunchTime%
SetDialogProperty>Excelo,scrapQuantity,Caption,%scrapQTY%
SetDialogProperty>Excelo,FPP,Caption,%feetPP%
SetDialogProperty>Excelo,PM,Caption,%peicesPM%
SetDialogProperty>Excelo,totalPunchTime,Caption,%shtPunchedSec%
VBEval>FormatNumber(%shtPunchedSec%,7),theResult
END>CalcVal
Show>Excelo,Dia1
If>Dia1=1
MessageModal>Processed!
EndIf
AddDialogHandler>Excelo,buttonCalculate,OnClick,CalcVal
SRT>CalcVal
GetDialogProperty>Excelo,jobSheets,Text,jobShts
GetDialogProperty>Excelo,sheetSize,Text,sheetSz
GetDialogProperty>Excelo,totalUnits,Text,ttlUnits
GetDialogProperty>Excelo,sheetCutSec,Text,sheetCutSec
GetDialogProperty>Excelo,sheetItems,Text,shtItems
GetDialogProperty>Excelo,sheetPunchedSec,Text,shtPunchedSec
GetDialogProperty>Excelo,sheetK,Text,shtK
GetDialogProperty>Excelo,sheetC,Text,shtC
GetDialogProperty>Excelo,sheetM,Text,shtM
GetDialogProperty>Excelo,sheetY,Text,shtY
GetDialogProperty>Excelo,selectedPrinter,Text,Prntr
GetDialogProperty>Excelo,totalFeet,Caption,ttlFeet
GetDialogProperty>Excelo,totalPunchTime,Caption,ttlPunchTime
GetDialogProperty>Excelo,scrapQuantity,Caption,scrapQTY
GetDialogProperty>Excelo,FPP,Caption,feetPP
GetDialogProperty>Excelo,PM,Caption,peicesPM
//Calculate Total Feet
Let>ttlFeet={(%sheetSz%/12)*%jobShts%}
//Calculate Total Pieces
Let>actPrinted=%shtItems%*%jobShts%
//Calculate Pieces / Min.
Let>ttlPPM={%actPrinted%/(%ttlFeet%*%Prntr%)}
//Calculate Ink Usages
Let>ttlInkK=shtK/ttlUnits
Let>ttlInkC=shtC/ttlUnits
Let>ttlInkM=shtM/ttlUnits
Let>ttlInkY=shtY/ttlUnits
Let>ttlInkUsed=shtK
Add>ttlInkUsed,shtC
Add>ttlInkUsed,shtM
Add>ttlInkUsed,shtY
//Calculate Total Punch Time
Let>shtPunchedSec={%shtPunchedSec%*(%jobShts%/60)}
//Calculate Scrap Quantity
Let>scrapQTY=%actPrinted%-%ttlUnits%
//Calculate Feet Per Peice
Let>feetPP=%ttlFeet%/%actPrinted%
//Calculate Total Punch Time
//Let>shtPunchedSec={%shtPunchedSec%*(%jobShts%/60)}
SetDialogProperty>Excelo,totalFeet,Caption,%ttlFeet%
SetDialogProperty>Excelo,actualPrinted,Caption,%actPrinted%
SetDialogProperty>Excelo,PPM,Caption,%ttlPPM%
SetDialogProperty>Excelo,unitK,Caption,%ttlInkK%
SetDialogProperty>Excelo,unitM,Caption,%ttlInkM%
SetDialogProperty>Excelo,unitC,Caption,%ttlInkC%
SetDialogProperty>Excelo,unitY,Caption,%ttlInkY%
SetDialogProperty>Excelo,totalInk,Caption,%ttlInkUsed%
SetDialogProperty>Excelo,totalPunchTime,Caption,%ttlPunchTime%
SetDialogProperty>Excelo,scrapQuantity,Caption,%scrapQTY%
SetDialogProperty>Excelo,FPP,Caption,%feetPP%
SetDialogProperty>Excelo,PM,Caption,%peicesPM%
SetDialogProperty>Excelo,totalPunchTime,Caption,%shtPunchedSec%
VBEval>FormatNumber(%shtPunchedSec%,7),theResult
END>CalcVal
Show>Excelo,Dia1
If>Dia1=1
MessageModal>Processed!
EndIf
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
Here is a different approach (without VB), but in the 2nd example, you will see one of the sortcomings.
Code: Select all
Let>DecimalConverter=1000000
Let>NumVal=10.987648915346
Let>NumVal={Trunc(%NumVal%*%DecimalConverter%)}
Let>NumVal={%NumVal%/%DecimalConverter%}
MDL>NumVal
Let>NumVal2=4.1
Let>NumVal2={Trunc(%NumVal2%*%DecimalConverter%)}
Let>NumVal2={(%NumVal2%/%DecimalConverter%)}
MDL>NumVal2
I've always done this using the round function. The round function might change the last digit of the resulting number but that is the result I've always wanted. For example if the resulting seven decimal place number ends in zero do you really want the last number to be a zero? If yes then the round function is not what you want.
Code: Select all
//Decimal places = number of zeros
//7 decimal places would mean var "places" has 7 zeros
Let>Places=10000000
Let>number=10.987648915346
Let>newnumber={(round(%number%*%places%))/%places%}
MDL>Newnumber
-
- Newbie
- Posts: 15
- Joined: Thu Aug 30, 2012 2:42 pm
- Location: United States
- Contact:
JRL! Thats exactly what I was trying to do yesterday with this code. I could not for the life of me figure out hot to calculate the math with the round function. I tried looking through the help file for how to use it but was not successful. Thanks for explaining it. I bet this will work exactly for what I am needing to do. Thanks for all your help guys! I will give it a try and let you know how it comes out.
Nick
Nick