Round Double Type value to Two decimal place in lotuscript

Posted on 2012-08-20
Medium Priority
Last Modified: 2013-12-18
How do you round 4.68079444599355E-04 to two decimal places.  Lotusscript Rounding returns 0 and Evaluate @Round return OverFlow Error.

Here is my code.

'Initialize Varibles
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim doc, pdoc As notesDocument
      Dim PCDayWk100 As Integer 'User Entry
      Dim NCDayWk100 As Double
      Dim NCDayWk120 As Double
      Dim Yrly100Demand As Double
      Dim SecPerHr As Integer 'Profile Retrieved
      Dim HrsPerShift As Double 'Profile Retrieved
      Dim NoOfShifts As Double 'User Entry
      Dim DayPerYr As Double 'Profile Retrieved
      Dim PCT As Double'User Entry
      Dim NoOfLines As Double 'User Entry
      Dim PCYrlyDemand As Double
      Dim dataEntrySum  As Double
      Dim PCYrlyDemandDivDataEntrySum  As Double
      'Set Variables
      Set db = ses.CurrentDatabase
      Set pdoc = db.GetProfileDocument("DBProfile")
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.Document
      If Not uidoc.FieldGetText("PCDayWk100") = "" Then
            PCDayWk100= uidoc.FieldGetText("PCDayWk100")
            NoOfShifts= uidoc.FieldGetText("NoOfShifts")
            Yrly100Demand = getYrlyDemandCol(db, doc.WrkCellID(0))
            PCT= uidoc.FieldGetText("PCT")
            HrsPerShift = pdoc.HrPerShift(0)
            DayPerYr = pdoc.DaysPerYear(0)
            SecPerHr = pdoc.SecPerHr(0)
            NoOfLines = doc.NoLines(0)
            'Perform Calculation
            PCYrlyDemand = PCDayWk100 * Yrly100Demand
            dataEntrySum = NoOfLines * SecPerHr * HrsPerShift * NoOfShifts * DayPerYr
            'dataEntrySumDivPCT = dataEntrySum / PCT
            PCYrlyDemandDivDataEntrySum = PCYrlyDemand / dataEntrySum
            NCDayWk100 =PCYrlyDemandDivDataEntrySum  / PCT
            newValue =  Evaluate("@Round(" & NCDayWk100 & ", 2)")
            Call uidoc.FieldSetText("NCDayWk100", Cstr(NCDayWk100))
            'Set Needed Capacity @120%
            NCDayWk120= NCDayWk100   * 1.2
            Call uidoc.FieldSetText("NCDayWk120", Cstr(NCDayWk120))
      End If
Question by:Robert Treadwell
  • 6
  • 2
LVL 43

Expert Comment

by:Steve Knight
ID: 38315122
Aside from any other functions in general to round to two decimal places you can just multiply by 100, take Integer of it and divide by 100.

BUT 4.68079444599355E-04 = 0.000468079444599355

So rounded to two spaces it IS "0"

LVL 43

Accepted Solution

Steve Knight earned 2000 total points
ID: 38315142
Hmm re-reading are you just saying you want it to say 4.68E-04 then?


LVL 46

Expert Comment

by:Sjef Bosman
ID: 38315150
You have good eyes, Sir! :-)

As far as the Overflow Error is concerned:
      newValue =  Evaluate("@Round(" & NCDayWk100 & ", 2)")
contains a formula error. Try to find the four-pixel difference with this line:
      newValue =  Evaluate("@Round(" & NCDayWk100 & "; 2)")

Points to Dragon-IT!
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 43

Expert Comment

by:Steve Knight
ID: 38315171
Yes good point there Sjef, I didn't actually look at the evaluated command since I knew it was going to be 0 (or error in this case).

LVL 43

Expert Comment

by:Steve Knight
ID: 38356948
rtreadwell - are you there?
LVL 43

Expert Comment

by:Steve Knight
ID: 38383878
Well thankyou for the points and grade.... tipped me over into being a "Guru" apparently ... another 10 years and could make a wizard if Notes is still around...

Lotus Notes points: 151546
148454 more points to become a Wizard in Lotus Notes!

LVL 46

Expert Comment

by:Sjef Bosman
ID: 38384878
Congrats! And a little focus might get you there sooner... :-)
LVL 43

Expert Comment

by:Steve Knight
ID: 38384902
Yeah, inbetween running a business, fixing everyone else's problems and looking after the kids you mean :-)

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question